How do I remove the points in XYLineAndShapeRenderer?

狂风中的少年 提交于 2021-02-05 07:32:28

问题


I'm making an application in Java using JFreeChart which shows an XY line chart. The problem is that it shows every point of the dataset on the lines, and I don't want to display these points. Any idea on how to remove the points or make them not visible?

This is a sample screenshot:

Here is the code:

JFrame frame = new JFrame();                
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesPaint(0, Color.RED);
renderer.setSeriesStroke(0, new BasicStroke(2.0f, 
BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
    new float[] { 2.0f, 4.0f }, 0.0f));
XYDataset ds = createDataset(i, p, capacity);
JFreeChart xylineChart = ChartFactory.createXYLineChart("", "", 
"", ds, PlotOrientation.VERTICAL, true, true, false);
XYPlot plot = xylineChart.getXYPlot();
plot.setDomainGridlinePaint(Color.BLACK);
plot.setRangeGridlinePaint(Color.BLACK);
plot.setBackgroundPaint(Color.WHITE);
plot.setRenderer(renderer);
ChartPanel cp = new ChartPanel(xylineChart);
frame.getContentPane().add(cp);

回答1:


By default, the no-argument constructor of XYLineAndShapeRenderer "Creates a new renderer with both lines and shapes visible." To remove the points, you can

  • Use the alternative constructor to specify the desired combination—lines without shapes, as shown here and in ChartFactory.createXYLineChart:

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    
  • Invoke setSeriesShapesVisible(), as @abhinavxeon suggests here and the author suggests here:

    renderer.setSeriesShapesVisible(0, false)
    


来源:https://stackoverflow.com/questions/54804499/how-do-i-remove-the-points-in-xylineandshaperenderer

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