Changing line plot thickness and resetting the axis.

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Euden
Posts: 1
Joined: Wed Nov 07, 2012 12:41 am
antibot: No, of course not.

Changing line plot thickness and resetting the axis.

Post by Euden » Wed Nov 07, 2012 7:14 pm

Hi there,

I'm using an adapted version of the Dynamic Data Demo 3 graph from the library, and I would like to change the thickness of the line and reset the graph at the push of a button, in other words have both x & y axis reset to 0 and start again.

Are there ways of doing this?

This is the basic code I'm using to initialise the chart:

Code: Select all


    /** The number of subplots. */
    public static final int SUBPLOT_COUNT = 1;
    
    /** The datasets. */
    protected XYSeriesCollection[] datasets;
    
    /** The most recent value added to series 1. */
    protected double[] lastValue = new double[SUBPLOT_COUNT];
    JPanel content;
    ChartPanel chartPanel;

        final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("intervals"));
        this.datasets = new XYSeriesCollection[SUBPLOT_COUNT];
        
        
            this.lastValue[0] = 100.0;
            final XYSeries series = new XYSeries("Seconds");
            this.datasets[0] = new XYSeriesCollection(series);
            final NumberAxis rangeAxis = new NumberAxis("tx");
            rangeAxis.configure();
            rangeAxis.setAutoRangeIncludesZero(true);
            final XYPlot subplot = new XYPlot(
                    this.datasets[0], null, rangeAxis, new StandardXYItemRenderer()
            );
            
            
            
            
            subplot.setBackgroundPaint(Color.black);
            subplot.setDomainGridlinePaint(Color.white);
            subplot.setRangeGridlinePaint(Color.white);
            subplot.setRangeCrosshairPaint(Color.white);
            
            subplot.getRenderer().setSeriesPaint(0, Color.green);
            
            plot.add(subplot);
        

        final JFreeChart chart = new JFreeChart("Demo", plot);

        chart.setBorderPaint(Color.black);
        chart.setBorderVisible(true);
        chart.setBackgroundPaint(Color.white);
        
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        
        
        
        final ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        
        
        
        content = new JPanel(new BorderLayout());

        chartPanel = new ChartPanel(chart);
        content.add(chartPanel);
The plotting on the graph is simple, it looks for files in ascending order according to another program that is generating them and plots the first value as X and the second value as Y, if the file end.txt appears the graph resets and goes back to looking for 1.txt:

Code: Select all

int iteration = 1;
        while(true){
            if(new File(filePath.getPath() + "/" + "end.txt").exists()){
                iteration = 1;
                //reset axis here.
                File f = new File(filePath.getPath()+"/" + "end.txt");
                f.delete();
            }
            else{
                try{
                File file = new File (filePath.getPath() + "/"+ (iteration) + ".txt");
                BufferedReader scan = new BufferedReader(new FileReader(file));
                boolean reading = true;

                    while(reading){

                        String X = scan.readLine();
                        if(X.equals("null")){
                            break;
                        }
                        double time = Double.parseDouble(X);
                        String Y= scan.readLine();
                        double tx = Double.parseDouble(Y);
                        final Millisecond now = new Millisecond();
                        System.out.println("Now = " + now.toString());
                        demo.lastValue[0] = time;
                        demo.datasets[0].getSeries(0).add(demo.lastValue[0], tx);
                        scan.close();
                        file.delete();
                        reading = false;
                        Thread.sleep(1000);
                        iteration++;
                    }




                }

                catch(FileNotFoundException FNF){
                        System.out.println("File not found");                    
                        continue;
                    }
                catch(IOException IOE){

                }
                catch(InterruptedException IE){

                }
    
        }
Thanks for any help you can give.

Euden

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

Re: Changing line plot thickness and resetting the axis.

Post by John Matthews » Wed Nov 07, 2012 10:43 pm

This example overrides getItemStroke() to alter a line's appearance. To reset a series, you could removeSeries() from the chosen TimeSeriesCollection or delete() from a contained TimeSeries. This example is another variation on updating a chart dynamically.

Locked