JFreeChart:如何使系列不可见? [英] JFreeChart : How to make a series invisible?

查看:81
本文介绍了JFreeChart:如何使系列不可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图使Ohlc柱形图不可见,以便我仅可以使用移动平均线离开窗口. 这是两个系列的代码(高低杠和移动平均线):

I am trying to make a chart of ohlc bars invisible so that I can leave the window with only the moving average. Here is the code with the two series (ohlc bars and moving average) :

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函数无法正常工作. 有任何想法吗? 谢谢.

For some reason setSeriesVisible function is not working. Any ideas? Thank you.

推荐答案

HighLowRenderer会忽略getSeriesVisible()getBaseSeriesVisible(),尽管进行getDrawOpenTicks()getDrawCloseTicks()的检查.您可以替换OHLCDataset:

HighLowRenderer ignores getSeriesVisible() and getBaseSeriesVisible(), although it does check getDrawOpenTicks() and getDrawCloseTicks(). You can replace the OHLCDataset:

plot.setDataset(0, null);

或者,不要首先添加OHLCDataset;只需使用它来创建MovingAverage.

Alternatively, don't add the OHLCDataset in the first place; just use it to create the MovingAverage.

这篇关于JFreeChart:如何使系列不可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆