skiabox
skiabox

Reputation: 3507

JFreeChart : How to make a series invisible?

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

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

Upvotes: 2

Views: 1693

Answers (1)

trashgod
trashgod

Reputation: 205875

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

plot.setDataset(0, null);

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

Upvotes: 2

Related Questions