Hello
I am drawing an line chart based on an XYDataset. I would like to give my users the option to reverse the direction of the chart. That is if the domain axis is from 1 to 60, I would like to plot the 60th value on the left side of the chart and the first value on the right. I have set up my code such that it should do that but the first value is always plotted on the left.
This is how I create the dataset from a double array which has already been set up with the last value at the zero index. ChartSeriesInfo is just an object I create to hold the double array plus some other stuff.
protected static XYSeriesCollection GetXYSeriesDataset(ArrayList Infos,double XaxisStart,boolean r2l)
{
XYSeriesCollection dataset = new XYSeriesCollection();
int step = 1;
if(r2l)
step = -1;
for (int i=0; i < Infos.size() ; i++)
{
ChartSeriesInfo csi = (ChartSeriesInfo)Infos.get(i);
String SeriesName = csi.SeriesName;
XYSeries series = new XYSeries(SeriesName);
double xaxis = XaxisStart;
for (int j = 0; j < csi.Values.length; j++)
{
series.add(xaxis, csi.Values[j]);
xaxis+=step;
}
dataset.addSeries(series);
}
return dataset;
}
Does the domain axis always get sorted before plotting? Any insights would be much appreciated.
Regards
Doug Bath
reverse freechart plot direction
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Re: reverse freechart plot direction
When you create a new XYSeries, by default it has an 'autoSort' flag that is set to true, and therefore it sorts the data items in order of x-value. This is to be consistent with the TimeSeries class, where it usually makes sense to sort the data items. I'm not so sure (anymore) that this is a sensible default for the XYSeries class…but anyway, you can change it in the constructor:
It's not completely clear to me what you want to achieve, but keep in mind that you can simply invert the axis and have the data items plotted in reverse:
Code: Select all
public XYSeries(Comparable key, boolean autoSort)
Code: Select all
ValueAxis xAxis = plot.getDomainAxis();
xAxis.setInverted(true);
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Re: reverse freechart plot direction
Thanks very much for your help David. I will try both solutions. I am working with seismic data which traditionally is recorded from north to south or east to west with north or east to the right. My users like to look at their charts with the same orientation.
Regards
Doug
Regards
Doug