Multi Axis + multi dataset

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
bitos2002
Posts: 1
Joined: Mon May 03, 2010 2:10 pm
antibot: No, of course not.

Multi Axis + multi dataset

Post by bitos2002 » Mon May 03, 2010 2:27 pm

Hello all,

I have a problem and I would like someone can help me.

I want to make a chart with 4 axis, 1 Domain for all. I have 4 TimeSeriesCollection, and each one have one dataset, and each dataset have one serie (TimeSerie). I have make a class for manage the creation of all the chart. Here is where I create the Chart:

public CuadroGrafico(String pTitulo,
String pTituloX,
String pTituloY,
XYDataset pDataset,
boolean pLeyenda,
boolean pTooltips,
boolean pUrls) throws ParseException {

chart = ChartFactory.createTimeSeriesChart(
pTitulo,
pTituloX,
pTituloY,
pDataset,
pLeyenda,
pTooltips,
pUrls);

chart.setBackgroundPaint(Color.white);
DateFormat mediumFormatter = SimpleDateFormat.getDateTimeInstance( SimpleDateFormat.LONG, SimpleDateFormat.MEDIUM );
Date ahora = Calendar.getInstance().getTime();
chart.addSubtitle(new TextTitle("Fecha Generacion Gráfico : " + mediumFormatter.format(ahora)));
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setPaint(Color.black);
}

The previous code works correctly for one Axis , but when I want to add new Axis, and for each one assign a new dataset don't work, I have arrived to create the axis and assign the ranges for each one, but in the plot I can't see the graph, I only can see the first one with the four axis, and all the ranges and colors correctly. Can anyone tell me the way to add news axis and for each one configure the setDataset, RangeAxis, mapDatasetToDomainAxis, mapDatasetToRangeAxis. My code to add a new graph to the plot is the following:

public void addPluma(String pTitulo,
Color pColorPluma,
TimeSeriesCollection pDataset,
int pIndiceDataset
) {

// Nueva Pluma
// Añadir Eje Y
NumberAxis axis = new NumberAxis(pTitulo);
axis.setAutoRangeIncludesZero(false);
axis.setLabelPaint(pColorPluma);
axis.setTickLabelPaint(pColorPluma);

XYPlot plot = this.chart.getXYPlot();
plot.setRangeAxis(pIndiceDataset , axis);
plot.setRangeAxisLocation(pIndiceDataset , AxisLocation.BOTTOM_OR_LEFT);
plot.setDataset(pIndiceDataset , pDataset);
plot.mapDatasetToDomainAxis(pIndiceDataset , 0);
plot.mapDatasetToRangeAxis(pIndiceDataset, plot.getDomainAxisIndex(axis));
plot.setWeight(3);


XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
renderer.setSeriesPaint(pIndiceDataset, pColorPluma);
}

If someone have done something similar can let me know how he have done.

Thank you very much
Oscar

Locked