【问题标题】:How to draw line over a JFreeChart chart?如何在 JFreeChart 图表上画线?
【发布时间】:2012-02-09 16:23:47
【问题描述】:

我有可更新的 OHLCChart。 我需要在图表上画一条线。

如何实现?

【问题讨论】:

    标签: java jfreechart


    【解决方案1】:

    如果要在轴上的给定位置绘制垂直或水平线,可以使用ValueMarker

    ValueMarker marker = new ValueMarker(position);  // position is the value on the axis
    marker.setPaint(Color.black);
    //marker.setLabel("here"); // see JavaDoc for labels, colors, strokes
    
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.addDomainMarker(marker);
    

    如果要绘制水平线,请使用plot.addRangeMarker()

    【讨论】:

    • 您可以使用 getXYPlot() 代替 getPlot() 和强制转换。
    【解决方案2】:

    如果您想绘制线指标(例如移动平均线),这样的方法应该可以工作:

        XYDataset dataSet = // your line dataset
    
        CombinedDomainXYPlot plot = (CombinedDomainXYPlot) chart.getPlot();
        XYPlot plot = (XYPlot) plot.getSubplots().get(0);
        int dataSetIndx = plot.getDatasetCount();
        plot.setDataset(dataSetIndx, dataSet);
    
        XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false);
        plot.setRenderer(dataSetIndx, lineRenderer);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多