home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
ib
/
setups
/
intrabld
/
data.z
/
CHART.CC
< prev
next >
Wrap
Text File
|
1996-12-11
|
5KB
|
145 lines
/****************************************************************************\
* *
* Chart.cc -- Custom Charting Controls *
* *
* Chart.cc contains a custom ActiveX chart control and a custom JavaApplet *
* chart control. These controls both have an Init() method that is used to *
* identify the fields that are used for the label and the data and the *
* rowset where data is located. See the Java.jfm and the ActiveX.jfm for *
* examples of using these controls. *
* *
* Dependencies: http://java.sun.com/applets/applets/BarChart/chart.class *
* *
* Updated 11/09/96 by IntraBuilder Samples Group *
* $Revision: 1.0 $ *
* *
* Copyright (c) 1996, Borland International, Inc. All rights reserved. *
\****************************************************************************/
class ActiveXChartQuery(FormObj) extends ActiveX(FormObj) custom {
with (this) {
height = 10;
width = 62;
classId = "clsid:FC25B780-75BE-11CF-8B01-444553540000";
params["ChartType"] = "8";
}
function Init(keyField, valueField, rowset)
{
this.keyField = keyField;
this.valueField = valueField;
this.rowset = rowset;
}
function onServerLoad()
{
var rowCount = 0;
var rowNames = "";
var data = this.rowset;
data.first();
while (!data.endOfSet) {
this.params["data[" + rowCount + "]"] = "" + data.fields[this.valueField].value;
var name = data.fields[this.keyField].value;
while ((pos = name.indexOf(" ")) > 0)
name = name.substring(0,pos) + "_" + name.substring(pos+1,name.length);
if (name.length == 0)
name = "Other";
rowNames += (name + " ");
rowCount++
data.next();
}
this.params["Rows"] = "" + rowCount;
this.params["RowNames"] = rowNames;
}
}
class JavaChartQuery(FormObj) extends JavaApplet(FormObj) custom {
with (this) {
height = 24;
width = 90;
code = "Chart.class";
codeBase = "http://java.sun.com/applets/applets/BarChart/";
params["orientation"] = "horizontal";
}
function Init(keyField, valueField, rowset)
{
this.keyField = keyField;
this.valueField = valueField;
this.rowset = rowset;
this.colors = {"pink","red","orange","yellow","green","cyan","blue","magenta","white"}
}
function onServerLoad()
{
var rowCount = 0,
largest = 0,
magnitude = 0;
var data = this.rowset;
data.first();
while (!data.endOfSet) {
rowCount++
var name = data.fields[this.keyField].value;
var sumTotal = data.fields[this.valueField].value;
if (name.length == 0)
name = "Other";
this.params["c" + rowCount] = sumTotal;
this.params["c" + rowCount + "_label"] = name;
this.params["c" + rowCount + "_style"] = "solid";
this.params["c" + rowCount + "_color"] = this.colors[rowCount%this.colors.length]
largest = (sumTotal > largest ? sumTotal : largest);
data.next();
}
this.params["columns"] = "" + parseInt(rowCount);
//
// calculate the magnitude of largest value
//
while (largest > 400) {
magnitude++;
largest /= 10;
}
// set the title to show the scale
this.params["title"] = "Each unit represents 1" + new StringEx().replicate("0",magnitude);
//
// recalculate the values based on magnitude or largest value
//
magnitude = Math.pow(10,magnitude);
for (var i = 1; i<=rowCount; i++) {
this.params["c" + i] = "" + parseInt(this.params["c"+i]/magnitude);
}
//
// Set the scale param to make maximum use of this area
if (largest <= 45)
this.params["scale"] = "10";
else if (largest <= 50)
this.params["scale"] = "9";
else if (largest <= 55)
this.params["scale"] = "8";
else if (largest <= 65)
this.params["scale"] = "7";
else if (largest <= 70)
this.params["scale"] = "6";
else if (largest <= 85)
this.params["scale"] = "5";
else if (largest <= 105)
this.params["scale"] = "4";
else if (largest <= 140)
this.params["scale"] = "3";
else if (largest <= 210)
this.params["scale"] = "2";
else
this.params["scale"] = "1";
}
}