Dynamically repaint ScatterPlot in jfreechart

I have a scatterplot which plots positions of agents. These positions change. I was wondering how can I repaint/redraw the scatterplot with the new positions my drawing method. I need to redraw in the updatePositions function. Is there any way to implement any listener for ScatterPlot? private ChartPanel createPanel() { JFreeChart jfreechart = ChartFactory.createScatterPlot( title, "", "", initPositions(),PlotOrientation.VERTICAL, true, true, false); XYPlot xyPlot = (XYPlot) jfreechart.getPlot(); xyPlot.setDomainCrosshairVisible(true); xyPlot.setRangeCrosshairVisible(true); XYItemRenderer renderer = xyPlot.getRenderer(); renderer.setSeriesPaint(0, Color.blue); adjustAxis((NumberAxis) xyPlot.getDomainAxis(), true); adjustAxis((NumberAxis) xyPlot.getRangeAxis(), false); xyPlot.setBackgroundPaint(Color.white); return new ChartPanel(jfreechart); } private void adjustAxis(NumberAxis axis, boolean vertical) { axis.setRange(-1, lattice+1); axis.setTickUnit(new NumberTickUnit(1)); axis.setVerticalTickLabels(vertical); } private XYDataset initPositions() { XYSeriesCollection xySeriesCollection = new XYSeriesCollection(); for (int i = 0; i < populationSize; i++) { if(population.get(i).status==1){ healthy.add(population.get(i).position[0], population.get(i).position[1]); }else if(population.get(i).status==2){ infected.add(population.get(i).position[0], population.get(i).position[1]); }else if(population.get(i).status==3){ recovered.add(population.get(i).position[0], population.get(i).position[1]); } } xySeriesCollection.addSeries(healthy); xySeriesCollection.addSeries(infected); xySeriesCollection.addSeries(recovered); return xySeriesCollection; } public void clear(){ healthy.clear(); infected.clear(); recovered.clear(); } public void updatePositions(ArrayList pop ){ population = pop; for (int i = 0; i

以上就是Dynamically repaint ScatterPlot in jfreechart的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准