I have a chart displaying correctly the first time.
The chart is created in an action button - GraphNow
The action method of the button
================= code start ================
dataCollection = new TimeSeriesCollection();
TimeSeries[] graphValues = new TimeSeries[ curListIndex] ;
for ( int line = 0; line < curListIndex; line++ )
{
graphValues[ line ] = new TimeSeries( (String)ipList.get(line), Minute.class );
....
int points = workingList.size();
for ( int point=0; point < points; point++ )
{
GraphData gd = (GraphData) workingList.get( point );
Date d = new Date( gd.x * (long)60000) ;
graphValues[ line ].add( new Minute(d) , (double)gd.y );
}
dataCollection.addSeries( graphValues[line] );
}
DateAxis domain = new DateAxis( "Time" );
NumberAxis range = new NumberAxis( yAxisLabel );
XYPlot plot = new XYPlot(dataCollection, domain, range, renderer);
.... plot and renderer calls skipped.
JFreeChart chart = new JFreeChart(
chartHeading, JFreeChart.DEFAULT_TITLE_FONT, plot, true
);
chart.setBackgroundPaint(Color.white);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPopupMenu(null);
getContentPane().add(chartPanel);
================= code end ================
The above displays the chart the first time it is called - after that the displayed valued do not change.
The user can change the time scale or type of values being graphed.
The result is the local TimeSeries values are updated and the
local TimeSeriersCollection are updated - actually they are both
new instances.
Then a new JFreeChart is created using the 'new' data.
BUT, the chart displayed to the user is not changed.
In the user guide I could not find anything about clearing the old dataset.
Should I be making the JFreeChart have the scope of my applet instead
of new'ing it each time the user clicks on GraphNow?
Any guidance is appreciated.
Thanks.
How do you change the chart values after it has been display
-
- Posts: 26
- Joined: Tue Jul 25, 2006 9:16 pm
- Location: Newburyport, MA USA
- Contact:
-
- Posts: 26
- Joined: Tue Jul 25, 2006 9:16 pm
- Location: Newburyport, MA USA
- Contact:
Result of additional test
I changed the code so the graph did not initially display.
Now, when you click on the GraphNow button the chart does not display.
I think the problem involved setting the graph panel via the setContentPane.
I need a way to set a JPanel to be a ChartPanel after it is created - maybe?
JFreeChart chart = new JFreeChart(
chartHeading, JFreeChart.DEFAULT_TITLE_FONT, plot, true
);
ChartPanel chartPanel = new ChartPanel(chart);
getContentPane().add(chartPanel);
I've created a JPanel
private javax.swing.JPanel graphPanel;
but don't know how to assign the ChartPanel to the JPanel,
graphPanel.add( chartPanel ) does not work.
Now, when you click on the GraphNow button the chart does not display.
I think the problem involved setting the graph panel via the setContentPane.
I need a way to set a JPanel to be a ChartPanel after it is created - maybe?
JFreeChart chart = new JFreeChart(
chartHeading, JFreeChart.DEFAULT_TITLE_FONT, plot, true
);
ChartPanel chartPanel = new ChartPanel(chart);
getContentPane().add(chartPanel);
I've created a JPanel
private javax.swing.JPanel graphPanel;
but don't know how to assign the ChartPanel to the JPanel,
graphPanel.add( chartPanel ) does not work.
-
- Posts: 18
- Joined: Thu May 11, 2006 11:22 pm
First, DON'T re-instantiate the chart to update it. You can end up with a memory leak that way - because of the wide variety of listeners between charts and chartPanels and so on, the old chart objects are likely to still have references and not be properly disposed. I wrestled with that one for a while...
I doubt this is the best answer, but if you do a removeAll() from your dataset and then re-add the (updated) series, the chart should notice the changes and update.
I doubt this is the best answer, but if you do a removeAll() from your dataset and then re-add the (updated) series, the chart should notice the changes and update.
-
- Posts: 26
- Joined: Tue Jul 25, 2006 9:16 pm
- Location: Newburyport, MA USA
- Contact:
How to chage the chart style after it was created
I have a similar question. After I created a chart, for example, bar chart with labels and legend, and displayed. How shall I display it without labels and legend upon an resize event. The event part is fine with me, I wonder how to draw/display the chart after this event.
Thanks in advance.
Thanks in advance.