How to dynamically update HistogramDataset with two series in jfreechart?

我们两清 提交于 2020-01-07 03:49:46

问题


I want to dynamically update two separate series in a jfree chart histogram. When i look at HistogramDataset it doesn't seem like there is a method for that. Is this possible? I know it can be done in SimpleHistogramDataset but I need to have two series on this chart.


回答1:


Some alternatives:

  1. Replace the HistogramDataset with each update:

    chart.getXYPlot().setDataset(newDataset);
    
  2. Add a second SimpleHistogramDataset and XYItemRenderer to the plot:

    SimpleHistogramDataset newDataset = createDataset();
    chart.getXYPlot().setDataset(1, newDataset);
    XYItemRenderer renderer = new XYBarRenderer();
    renderer.setBasePaint(Color.blue);
    chart.getXYPlot().setRenderer(1, renderer);
    
  3. Create a custom AbstractIntervalXYDataset that supports mutation.



来源:https://stackoverflow.com/questions/44688808/how-to-dynamically-update-histogramdataset-with-two-series-in-jfreechart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!