Page 1 of 1

Selective shapes on a line

Posted: Wed Dec 07, 2011 4:30 pm
by IanHayes

I am writing a cricket scoring system for my school computing course. I am using JFreecharts to produce a few charts. On a couple of the charts, I want to put a shape on the line selectively. It is standard practice in cricket to mark charts with the fall of a wicket. for instance the cumulative run rate chart or the run rate chart need this. I have found out how to put shapes on the line, but I just get all shapes at change points on the line. Here is some of my code that I have used so far (I am using NetBeans if that is important): -

Code: Select all

        JFreeChart chart = ChartFactory.createXYLineChart("Cumulative Runs", // Title 
           "Overs", // x-axis Label 
           "Runs", // y-axis Label 
           dataset, // Dataset 
           PlotOrientation.VERTICAL, // Plot Orientation 
           true, // Show Legend 
           true, // Use tooltips 
           false // Configure chart to generate URLs? 

        XYPlot plot = chart.getXYPlot();
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)
        BufferedImage image = chart.createBufferedImage(600,400);
        jChartArea.setIcon(new ImageIcon(image));
        this.setSize(610, 450);

Re: Selective shapes on a line

Posted: Tue Jul 17, 2012 9:14 pm
by david.gilbert
There's no out-of-the-box way to do that with JFreeChart, but if you don't mind subclassing the renderer (XYLineAndShapeRenderer) you could override the getItemShapeVisible(int series, int item) method to control whether or not a shape is drawn for each datapoint. (In JFreeChart, not Eastwood - I think you posted in the wrong forum, and then of course I replied much too late to be useful :oops: ).