2

我正在尝试使 ohlc 条形图不可见,这样我就可以只留下移动平均线的窗口。这是两个系列的代码(ohlc 条和移动平均线):

private static JFreeChart createChart(OHLCDataset dataset)
{
    JFreeChart chart = ChartFactory.createHighLowChart(
            "HighLowChartDemo2",
            "Time",
            "Value",
            dataset,
            true);

    XYPlot plot = (XYPlot)chart.getPlot();

    DateAxis axis = (DateAxis)plot.getDomainAxis();
    axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
    yAxis.setNumberFormatOverride(new DecimalFormat("$0.00"));

    //overlay the moving average dataset...
    XYDataset dataset2 = MovingAverage.createMovingAverage(dataset, "-MAVG", 3 * 24 * 60 * 60 * 1000L, 0L);
    plot.setDataset(1, dataset2);
    plot.setRenderer(1, new StandardXYItemRenderer());

    XYItemRenderer theRenderer = plot.getRenderer(0);
    theRenderer.setSeriesVisible(0, false);

    return chart;
}

由于某种原因 setSeriesVisible 函数不起作用。有任何想法吗?谢谢你。

4

1 回答 1

2

HighLowRenderer忽略getSeriesVisible()and getBaseSeriesVisible(),尽管它确实检查getDrawOpenTicks()and getDrawCloseTicks()。您可以替换OHLCDataset

plot.setDataset(0, null);

或者,不要一开始就添加OHLCDataset;只需使用它来创建MovingAverage.

于 2012-07-02T14:43:22.483 回答