Trying to make one of the two series invisible

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
skiabox
Posts: 7
Joined: Mon Apr 16, 2012 2:29 pm
antibot: No, of course not.

Trying to make one of the two series invisible

Post by skiabox » Mon Jul 02, 2012 2:52 pm

I have two series of data , an OHLC series and a moving average of this OHLC series.
I am trying to make the OHLV bars invisible , so that I can stay with only the moving average in the plot window.
Here is the code :

Code: Select all

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 guys?
Thank you.

skiabox
Posts: 7
Joined: Mon Apr 16, 2012 2:29 pm
antibot: No, of course not.

Re: Trying to make one of the two series invisible

Post by skiabox » Mon Jul 02, 2012 4:48 pm

I found a solution : plot.setDataset(0, null);

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Trying to make one of the two series invisible

Post by John Matthews » Wed Jul 04, 2012 4:40 am

See also this Q&A.

Locked