2012-02-09 79 views

回答

18

如果你想上的軸的給定位置繪製垂直或水平線,你可以使用一個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()如果你想畫的水平線。

+0

對我來說完美的答案:) – 2017-11-13 14:27:19

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);