two diffrent Series in one dataset...

Discussion about JFreeChart related to stockmarket charts.
Locked
blone
Posts: 2
Joined: Fri Feb 11, 2005 4:16 pm

two diffrent Series in one dataset...

Post by blone » Thu Mar 10, 2005 4:42 pm

Halo,

I've some problems with the jfreechart. I have as Input a StringTable
with some Values. In the row [0] are the timestamp of the other Values in
the comlums. At the moment the Service are include all Values of the Colums they are bigger then cero. This Values build the Lines in the Chart.
but now i will intecrate one more series, a timeseries for the X axis with the time Value from colum cero.
My Quetion; can someone explane me, how i can intecrate the timeseries to the xySeriesCollection dataset?
thank your for your help

greets Ben

So thats my source:


// pipeline
IDataCursor pipelineCursor = pipeline.getCursor();
String[] columnNames = IDataUtil.getStringArray( pipelineCursor, "columnNames" );
String[][] stringTable = IDataUtil.getStringTable( pipelineCursor, "stringTable" );
String filepath = IDataUtil.getString( pipelineCursor, "filepath" );
String timevalue = IDataUtil.getString( pipelineCursor, "timevalue" );
pipelineCursor.destroy();

XYSeriesCollection dataset = new XYSeriesCollection();
for ( int col = 1; col < columnNames.length; col++ )
{
XYSeries series = new XYSeries(columnNames[col]);
for (int row = 0; row < stringTable.length; row++)
{
double x = (double) row;
double y = Double.parseDouble(stringTable[row][col]) * Double.parseDouble(timevalue);
series.add(x, y);
}
dataset.addSeries(series);
}

JFreeChart chart = ChartFactory.createXYLineChart(
null, // chart title
null, // x axis label
null, // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
false, // tooltips
false // urls
);


// SOME OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);

StandardLegend legend = (StandardLegend) chart.getLegend();
legend.setDisplaySeriesShapes(true);

// get a reference to the plot for further customisation...
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

plot.setDomainCrosshairLockedOnData(true);
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairLockedOnData(true);
plot.setRangeCrosshairVisible(true);

StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
renderer.setDefaultShapesFilled(Boolean.TRUE);
renderer.setItemLabelsVisible(true);

// change the auto tick unit selection to integer units only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
try
{
ChartUtilities.saveChartAsPNG(new File(filepath), chart, 200, 150);
}
catch (java.io.IOException exc)
{
System.err.println("error writing image to file");
}

Locked