replacing one chart with another

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Allyson Gwin

replacing one chart with another

Post by Allyson Gwin » Thu Feb 06, 2003 5:50 pm

I have a space on my form that I am using for all my charts. When the user enters the form, they see the beginning chart. Depending on things they click on the form, the chart may become a whole new chart. I don't know how to get this new chart to display.

Here is the original chart:

// create the chart...
ChartPanel chartPanel;
JFreeChart chart = ChartFactory.createLineXYChart("", // chart title
"Site--Azimuth (Surveyed)", // x axis label
"Vertical Angle", // y axis label
dataset, // data
true, // include legend
true, // tooltips
false // urls
);

// get a reference to the plot for further customisation...
XYPlot plot = chart.getXYPlot();

// set the color for each series...
plot.setSeriesPaint(new Paint[] { Color.black, Color.green, Color.blue });

// add the chart to a panel...
chartPanel = new ChartPanel(chart);
chartPanel.setBounds(new Rectangle(3, 518, 826, 212));
jPanel1.add(chartPanel, null);

And here is the new chart:

// create the chart...
ChartPanel chartPanel;
JFreeChart chart = ChartFactory.createLineXYChart("", // chart title
"Object--Azimuth (Surveyed)", // x axis label
"Vertical Angle", // y axis label
dataset, // data
true, // include legend
true, // tooltips
false // urls
);

// get a reference to the plot for further customisation...
XYPlot plot = chart.getXYPlot();
plot.setSeriesPaint(new Paint[] { Color.blue });
// set the color for each series...
// plot.setSeriesPaint(new Paint[] { Color.black, Color.green, Color.blue });

// add the chart to a panel...
chartPanel = new ChartPanel(chart);
chartPanel.setBounds(new Rectangle(3, 518, 826, 212));
jPanel1.add(chartPanel, null);

dataset is different in both charts, but the second one never appears. I have printed out the items in the dataset and the series and they match what should be in the second chart. Is there something that I need to clear out first? Thanks.

Allyson

David Gilbert

Re: replacing one chart with another

Post by David Gilbert » Fri Feb 07, 2003 1:17 pm

It's impossible to tell the context in which you run those two bits of code.

One suggestion...if you have a ChartPanel displaying one chart, you can always create a new chart and then:

myChartPanel.setChart(myNewChart);

...to change the chart that is being displayed in the panel.

Regards,

Dave Gilbert

Locked