Jfreechart - 根据变化的数据刷新图表

发布于 2024-11-11 14:34:20 字数 202 浏览 3 评论 0原文

我想知道如果我们想“实时”更改某些数据,如何刷新图表。我的意思是,例如,我有一个包含 3 年任务系列的图表,我想将 3 年更改为 5 年。我希望图表立即改变。

有某种更新图表或类似的东西吗?

我知道您可能会说“获取您的任务系列,进行更改,它将自动刷新”,但我的任务系列已生成,我无法轻松更改这些任务系列。这就是为什么我想找到一种方法来重新计算并重建整个图表。

I would like to know how to refresh a chart if we want to change "in live" some piece of data. I mean for instance, I have a chart with a TaskSeries which appears on 3 years and I would like to change 3 years by 5 years. I want the chart to change immediately.

Is there some kind of update chart or something like that ?

I know that you could say "get your TaskSeries, do your changes and it will be refreshed automatically" but my TaskSeries are generated and I cannot easily change these ones. That's why I would like to find a way to recalculate and to rebuild the whole chart.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

花间憩 2024-11-18 14:34:20

TaskSeries 自动发送 SeriesChangeEvent 到所有已注册的侦听器,例如 CategoryPlot。在此示例中, DynamicTimeSeriesCollection 实现 <代码>SeriesChangeEvent。在本例中,图表的 XYPlot 是已注册的侦听器。

The add() method of TaskSeries automatically sends a SeriesChangeEvent to all registered listeners, e.g. CategoryPlot. In this example, DynamicTimeSeriesCollection implements SeriesChangeEvent. In this case, the chart's XYPlot is a registered listener.

野稚 2024-11-18 14:34:20

我在使用 XYPlot 时也遇到了这个问题。我通过重置数据集找到了解决方法:

chart.getXYPlot().setDataset(chart.getXYPlot().getDataset());

这很疯狂,但它有效...

注意:chart.setNotify(true) 似乎什么也没做。

I had this issue too with an XYPlot. I found a workaround by resetting the dataset:

chart.getXYPlot().setDataset(chart.getXYPlot().getDataset());

that's crazy but it works...

Note: chart.setNotify(true) seems to do nothing.

蓝海 2024-11-18 14:34:20

我有这个问题;我用这个做到了:

private void refreshChart() {
    jPanel_GraphicsTop.removeAll();
    jPanel_GraphicsTop.revalidate(); // This removes the old chart 
    aChart = createChart(); 
    aChart.removeLegend(); 
    ChartPanel chartPanel = new ChartPanel(aChart); 
    jPanel_GraphicsTop.setLayout(new BorderLayout()); 
    jPanel_GraphicsTop.add(chartPanel); 
    jPanel_GraphicsTop.repaint(); // This method makes the new chart appear
}

I had this issue; I did it using this:

private void refreshChart() {
    jPanel_GraphicsTop.removeAll();
    jPanel_GraphicsTop.revalidate(); // This removes the old chart 
    aChart = createChart(); 
    aChart.removeLegend(); 
    ChartPanel chartPanel = new ChartPanel(aChart); 
    jPanel_GraphicsTop.setLayout(new BorderLayout()); 
    jPanel_GraphicsTop.add(chartPanel); 
    jPanel_GraphicsTop.repaint(); // This method makes the new chart appear
}
破晓 2024-11-18 14:34:20
// create a chart
ChartFrame mychartframe = new ChartFrame("my charts", chart);

// some other stuff ...

// somewhere else in a code far far away
mychartframe.getChartPanel().getChart().fireChartChanged();
// create a chart
ChartFrame mychartframe = new ChartFrame("my charts", chart);

// some other stuff ...

// somewhere else in a code far far away
mychartframe.getChartPanel().getChart().fireChartChanged();
一身仙ぐ女味 2024-11-18 14:34:20

对我有用的是以下内容:

//reset with new dataset
chart().setDataset(dataset);
repaint the ChartPanel that contains the JFreeChart
chartPanel.repaint();

What worked with me was the following:

//reset with new dataset
chart().setDataset(dataset);
repaint the ChartPanel that contains the JFreeChart
chartPanel.repaint();
╄→承喏 2024-11-18 14:34:20

我还没有找到一种简单的方法来“实时”更新 JFreeChart,因为 jfreechart 的数据结构与我的数据结构非常不兼容。因此,我构建了自己的 redraw() 方法,该方法从我的 dataModel 收集数据,构建 JFreeChart dataModel 并设置新的图表。

这给人一种“实时”更新的感觉,而且非常难看。

I haven't found an easy way to update a JFreeChart "live", since the data-structure of jfreechart is very incompatible to my data-structure. So I build a redraw()-Method of my own, that collects the data from my dataModel, build up a JFreeChart dataModel and set the chart new.

This gives the feeling of a "live" update, also it is very ugly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文