想要连续更新jfreechat xylinechart [英] Want to update jfreechat xylinechart continuously

查看:32
本文介绍了想要连续更新jfreechat xylinechart的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在netbeans swing中使用jfreechart创建了xyline图表.

I have xyline chart created using jfreechart inside netbeans swing.

我有两个文件,一个用于连续获取x和y坐标的值,另一个用于显示它们,现在我从显示文件的构造函数创建图表,并使用硬编码值显示图表,但是当我通过时我收到的图表未相应更新.

I have two files one is for getting values for x and y coordinates continuously and other is for display of them now I am creating the chart from constructor of the display file and it displays the chart using hard coded values but when I pass my incoming the chart is not updating accordingly.

请找到以下显示文件代码:

Please find below code for display file :

public Display_Unit_Mod() {

JPanel jPanel1 = createChartPanel();

}

public JPanel createChartPanel() {
    String chartTitle = "";
    String xAxisLabel = "x_value";
    String yAxisLabel = "y_value";
    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, 
            xAxisLabel, yAxisLabel, dataset);


    customizeChart(chart);


    return new ChartPanel(chart);
}

public XYDataset createDataset() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series1 = new XYSeries("");


    System.out.println(String.valueOf(test.x_value));
      System.out.println(String.valueOf(test.y_value));

            series1.add(test.x_value,test.y_value); ->test is the object of other file and using it I am taking values from there
            //series1.add(7.0,8.0);
            //series1.add(3.0,4.0); -> displays values and prints chart
            //series1.add(1.0,2.0);


    dataset.addSeries(series1);

    return dataset;
}

private void customizeChart(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    // sets paint color for each series
    renderer.setSeriesPaint(0, Color.RED);

    // sets thickness for series (using strokes)
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(2, new BasicStroke(2.0f));

    // sets paint color for plot outlines
    plot.setOutlinePaint(Color.BLUE);
    plot.setOutlineStroke(new BasicStroke(2.0f));

    // sets renderer for lines
    plot.setRenderer(renderer);

    // sets plot background
    plot.setBackgroundPaint(Color.DARK_GRAY);

    // sets paint color for the grid lines
    plot.setRangeGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.BLACK);

    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.BLACK);

    }

我可以看到这些值是由system.out.println来的,但并没有反映在UI上.

I can see the values coming by system.out.println but not getting reflected on UI.

请帮助我更新相同内容.

Please help me updating the same.

推荐答案

使用此处所示.在process()的实现中更新图表的数据集,如此处所示.该侦听图将作为响应进行更新.可以看到使用 SwingTimer 的相关示例此处.

Retrieve your data values in the background using a SwingWorker, as shown here. Update the chart's dataset in your implementation of process(), as shown here. This listening chart will update itself in response. A related example using SwingTimer is seen here.

这篇关于想要连续更新jfreechat xylinechart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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