使用 Java 和 JFreeChart 修改已构建图表的数据集 [英] modify dataset of an already built chart with Java and JFreeChart

查看:35
本文介绍了使用 Java 和 JFreeChart 修改已构建图表的数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Let's say I've generated a chart with the following code:

private ChartPanel createChart(){
        XYSeries series1 = new XYSeries("First");
        XYSeries series2 = new XYSeries("Second");
        XYSeries series3 = new XYSeries("Third");

        series1.add(0.0, 5.5);
        series1.add(5, 10);
        series1.add(10, 5.5);

        series2.add(0.0, 2);
        series2.add(5, 2);
        series2.add(10, 7);

        series3.add(0.0, 10);
        series3.add(5, 5);
        series3.add(10, 6);

        XYSeriesCollection dataset = new XYSeriesCollection();

        dataset.addSeries(series1);
        dataset.addSeries(series2);
        dataset.addSeries(series3);

        JFreeChart chart = ChartFactory.createXYLineChart("line chart example",
                "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
        ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        return chartPanel;
    }

Now I would like to modify a value previously inserted in an XYSeries without build another chart (no other call to createXYLineChart), and make the chart automatically updated.

How do this?

解决方案

Just look at the api.

There are many different methods, depending if you know the index of the element in the series, or if you know the x-value, but want to change the y-value. I assume the chart will be redrawn since all the methods throw a SeriesChangeEvent.

这篇关于使用 Java 和 JFreeChart 修改已构建图表的数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆