How can I fix a line chart with disconnected points

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
dipaca
Posts: 2
Joined: Mon Sep 02, 2013 6:06 pm
antibot: No, of course not.

How can I fix a line chart with disconnected points

Post by dipaca » Mon Sep 02, 2013 6:22 pm

Hi everyone, I need some help with a line chart problem. I'm totally new to JFreeChart so I'm sorry if asking this is somewhat stupid:

My problem is that, as you can see in the image below, one of the chart series is not connecting all of its points (the blue one). I'm wondering if is there any way to force the lines to be continuous.

Thanks!

Image

Code: Select all

public void graficaLineal(Object[][] datos, String TituloVentana, String TituloGrafica, String TituloX, String TituloY){
        
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();

        for(int i = 0; i < datos.length;i++){
            Number Numero = (Number)datos[i][0];
            String Texto1 = datos[i][1].toString();
            String Texto2 = datos[i][2].toString();
            dataset.addValue(Numero, Texto1, Texto2);
        }

        JFreeChart chart = ChartFactory.createLineChart(TituloGrafica, TituloX, TituloY,dataset,PlotOrientation.VERTICAL,true,true,false);
        
        ChartFrame frame = new ChartFrame(TituloVentana,chart);
        
        LineAndShapeRenderer renderer = (LineAndShapeRenderer) chart.getCategoryPlot().getRenderer();        

        Integer Filas = chart.getCategoryPlot().getDataset().getRowCount();        
        
        for(int i = 0; i < Filas;i++){
            renderer.setSeriesShapesVisible(i, true);
            renderer.setSeriesLinesVisible(i, true);
            renderer.setSeriesShapesFilled(i, true);
            renderer.setSeriesShape(i, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
        }
        
        for(int i = 0; i < chart.getCategoryPlot().getDataset().getRowCount();i++){
            if(((String)chart.getCategoryPlot().getDataset().getRowKey(i)).equals("Accidentes")){
                renderer.setSeriesPaint(i, Color.RED);
            }else if(((String)chart.getCategoryPlot().getDataset().getRowKey(i)).equals("Cuasi Accidentes")){
                renderer.setSeriesPaint(i, Color.BLUE);
            }else{
                renderer.setSeriesPaint(i, Color.GREEN);
            }
        }
        
        frame.setDefaultCloseOperation(ChartFrame.DISPOSE_ON_CLOSE);
        
        frame.setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE);
        
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        
    }
Last edited by dipaca on Tue Sep 03, 2013 2:39 am, edited 1 time in total.

dipaca
Posts: 2
Joined: Mon Sep 02, 2013 6:06 pm
antibot: No, of course not.

Re: How to fix a line chart with disconnected points

Post by dipaca » Tue Sep 03, 2013 2:45 am

wydrzyk wrote:Thank you very much!
Well, you're very welcome but I posted a problem, not a solution :lol: .

I hope somebody can help me out with it, since I've been reading many things about JFreeChart but haven't been able to find a solution yet :oops:

mkivinie
Posts: 51
Joined: Wed Jul 06, 2005 8:35 am

Re: How can I fix a line chart with disconnected points

Post by mkivinie » Thu Sep 05, 2013 1:45 pm

If you change your chart from CategoryChart to XYChart then you would get connected lines.
I am not familiar with CategoryChart so I do now know if it is also possible with that.

Locked