Article View: borland.public.jbuilder.java.language
Article #18089Re: Chart
From: claire Lecarpentier
Date: Wed, 19 Aug 1998 00:00
Date: Wed, 19 Aug 1998 00:00
85 lines
3681 bytes
3681 bytes
Suchitha,
You can use the JCChart. It is a KL Group bean that is filled from an array.
Here is the code of the array class :
import jclass.chart.Chartable;
import java.util.Vector;
public class ArrayData implements Chartable{
public double rawData[][]= new double[2][50];
Vector data = new Vector();
public ArrayData() {
makeData(rawData);}
public ArrayData(double data[][]) {
makeData(data);}
private void makeData(double array[][]) {
for (int i=0; i<array.length;i++){
Vector row = new Vector();
for (int j=0; j<array[i].length;j++){
row.addElement(new Double(array[i][j]));}
data.addElement(row);}}
public Object getDataItem(int row, int column){
Object rval = null;
try {rval = ((Vector)data.elementAt(row)).elementAt(column);}
catch (Exception ex){}
return rval;}
public Vector getRow(int row){
Vector rval = null;
try {rval = (Vector)data.elementAt(row);}
catch (Exception ex){}
return rval;}
public int getDataInterpretation(){
return ARRAY;}
public int getNumRows(){
if (data == null) return 0;
return data.size();}
public String[] getPointLabels(){
return null;}
public String getSeriesName(int row){
return null;}
public String getSeriesLabel(int row){
return getSeriesName(row);}
public String getName(){
return new String("Array Data");}
}
And here is the code for filling the array with the data countained in your
database :
int nb_rows=0;
It is what you will put in the array :
Variant v1=new Variant();
Variant v2=new Variant();
try {
I define the parameter row I need for the query :
pRow.setString("C_CompanyID",S_CompetitorID);
I execute the query :
qds_Chart1.executeQuery();
I store the number of records in the query :
nb_rows = qds_Chart1.getRowCount();
double tab_chart[][]=new double[2][nb_rows];
And I fill the array with the value of the fields :
if (nb_rows != 0){
for (int i=0;i<nb_rows;i++){
The fields are define as float in the database and as double in the
queryDataSet:
qds_Chart1.getVariant("year_fin",i,v1);
qds_Chart1.getVariant("net_sales",i,v2);
tab_chart[0][i]=v1.getAsDouble();
tab_chart[1][i]=v2.getAsDouble();
}
}
jCChart_Financial.getDataView(0).setDataSource(new
ArrayData(tab_chart));
I hope it will help you, good luck, Claire.
Suchitha Madapoosi a οΏ½crit:
> I am trying to create a chart using data from some database.I am using
> Jbuilder tool. I am open to any other tool if jbuilder doesn't support
> this. Help will be appreciated. I know you could do this using KLgroup.
> Please help me.
> Thanks
> Suchitha
Technical Details
Message-ID:
<35DA840B.B194F27B@casecorp.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35C91C11.93B6BB8F@home.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: f74b3,e46e72fae189a41e X-Google-Attributes: gidf74b3,public From: claire Lecarpentier <clecarpentier@casecorp.com> Subject: Re: Chart Date: 1998/08/19 Message-ID: <35DA840B.B194F27B@casecorp.com> X-Deja-AN: 382568133 Content-Transfer-Encoding: 8bit References: <35C91C11.93B6BB8F@home.com> To: Suchitha Madapoosi <suchitha@home.com> Content-Type: text/plain; charset=iso-8859-1 Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language