Returning the data displayed in the line chart current view

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Post Reply
TripVoltage
Posts: 1
Joined: Mon Mar 21, 2016 6:23 pm
antibot: No, of course not.

Returning the data displayed in the line chart current view

Post by TripVoltage » Mon Mar 21, 2016 6:46 pm

Hi I have created the following line chart:

Chart un-zoomed
Image

Chart zoomed
Image

I created the chart with XYSeriesCollection then added to it three XYSeries. The chart works great and I can zoom in and pan left and right.

My problem is that I'm trying to save the data currently displayed in the chart view for each of the datasets (in this case 3). The chart data is big so when a user is able to zoom in on a section I want them to be able to save the data shown in that section. I would appreciate help with this?

I tried this:

Code: Select all

org.jfree.data.Range xRange = plot.getDomainAxis().getRange();
    	org.jfree.data.Range yRange = plot.getRangeAxis().getRange();
    	ConsoleLog.DisplayToConsole(xRange.toString());
and this saves to an image what is currently displayed on the chart

Code: Select all

int width = 640; /* Width of the image */
        int height = 480; /* Height of the image */ 
        File file = new File( "LineChart.jpeg" ); 
        try {
			ChartUtilities.saveChartAsJPEG(file ,lineChart, width ,height);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
I'm assuming that if I can get the horozontal start and end index of the displayed data then I can use these index to access the ArrayList containing the data.

Thanks

Update:

I've found what I wanted:

Code: Select all

    	XYSeries series = data.getSeries(0);
		org.jfree.data.Range xRange = plot.getDomainAxis().getRange();
    	int x = (int) xRange.getLowerBound();
        int y = (int) xRange.getUpperBound();
    	ArrayList<String> list = new ArrayList<String>();
    	String s = "";

    	for(int i = x; i < y; i++)
    	{
    		s = String.valueOf(series.getY(i));
    		list.add(s);
    		ConsoleLog.DisplayToConsole(s);
    	}

Post Reply