Multiple TimeSeries scaling axis question

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Multiple TimeSeries scaling axis question

Post by tonyGriffiths » Wed Jun 21, 2006 10:43 am

I have a single graph that contains several timeseries, and uses multiple axes. However, whilst the time line for each series has the same date range, the values are on completely different scales.

I'd like to force the graph to scale each axis so that they all use the range [minValue - maxValue], where maxValue is the lartgest value used by *any* of the different timeseries.

Any ideas?

Thanks,

Tony[/img]

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Here's an answer

Post by tonyGriffiths » Wed Jun 21, 2006 11:04 am

Ok, so I'm replying to my own question, how sad!

I've found the method setRange(minValue,maxValue) on the NumberAxis class, and this works great.

Tony

manish
Posts: 10
Joined: Tue Aug 01, 2006 7:24 am

plz help

Post by manish » Tue Aug 01, 2006 1:28 pm

hi i have the same requirement so can u put little code how i can do this

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Post by tonyGriffiths » Tue Aug 01, 2006 2:09 pm

I've created a class that wraps the data for the graph. This has a method to return the maximum value for the timeseries.

Then I just do the following:

Code: Select all

public class MultipleTimeSeriesGraphCustomizer implements ChartPostProcessor {

  private MyGraphClass graphData;

  public void processChart(Object chart, Map params) {
    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();

    // Annulus A Pressure Axis
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    plot.getRangeAxis().setRange(0,graphData.getMaxValue());
...
}
}
Hope this helps,

Tony

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Post by tonyGriffiths » Tue Aug 01, 2006 2:10 pm

I've created a class that wraps the data for the graph. This has a method to return the maximum value for the timeseries.

Then I just do the following:

Code: Select all

public class MultipleTimeSeriesGraphCustomizer implements ChartPostProcessor {

  private MyGraphClass graphData;

  public void processChart(Object chart, Map params) {
    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();

    // Annulus A Pressure Axis
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    plot.getRangeAxis().setRange(0,graphData.getMaxValue());
...
}
}
Hope this helps,

Tony

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Post by tonyGriffiths » Tue Aug 01, 2006 2:10 pm

I've created a class that wraps the data for the graph. This has a method to return the maximum value for the timeseries.

Then I just do the following:

Code: Select all

public class MultipleTimeSeriesGraphCustomizer implements ChartPostProcessor {

  private MyGraphClass graphData;

  public void processChart(Object chart, Map params) {
    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();

    // Annulus A Pressure Axis
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    plot.getRangeAxis().setRange(0,graphData.getMaxValue());
...
}
}
Hope this helps,

Tony

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Post by tonyGriffiths » Tue Aug 01, 2006 2:26 pm

I've created a class that wraps the data for the graph. This has a method to return the maximum value for the timeseries.

Then I just do the following:

Code: Select all

public class MultipleTimeSeriesGraphCustomizer implements ChartPostProcessor {

  private MyGraphClass graphData;

  public void processChart(Object chart, Map params) {
    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();

    // Annulus A Pressure Axis
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    plot.getRangeAxis().setRange(0,graphData.getMaxValue());
...
}
}
Hope this helps,

Tony

tonyGriffiths
Posts: 11
Joined: Wed Jun 21, 2006 10:38 am

Post by tonyGriffiths » Tue Aug 01, 2006 2:26 pm

I've created a class that wraps the data for the graph. This has a method to return the maximum value for the timeseries.

Then I just do the following:

Code: Select all

public class MultipleTimeSeriesGraphCustomizer implements ChartPostProcessor {

  private MyGraphClass graphData;

  public void processChart(Object chart, Map params) {
    XYPlot plot = (XYPlot) ((JFreeChart) chart).getPlot();

    // Annulus A Pressure Axis
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.getRangeAxis().setFixedDimension(15.0);
    plot.getRangeAxis().setRange(0,graphData.getMaxValue());
...
}
}
Hope this helps,

Tony

manish
Posts: 10
Joined: Tue Aug 01, 2006 7:24 am

its urgent

Post by manish » Wed Aug 02, 2006 7:11 am

can u tell me how u put yr x axis .
becoz in my case i want its in mm-yyyy formate but not able to get it.
i am using xyseries and dont kow how to use time series so can u help me out.
i am puting my code>>>>>>>>>>
private JFreeChart createTimeSeriesChart(String sNDC, List listPBM, String sFromMonth, String sFromYear, String sToMonth, String sToYear) {

XYSeriesCollection dataset = new XYSeriesCollection();

try {
List listMaxAvgAmount = null;
Map mapMaxAvgAmount = new HashMap();
DateAxis dateAxis = null;
XYSeries series =null;
XYDataItem xyDataItem = null;
System.out.println("in servlet>>>>>..."+sFromMonth+">>>>>>"+sFromYear);
if(listPBM.size()>0)
{
for(int i=0;i<listPBM.size();i++)
{
series = new XYSeries((String)listPBM.get(i));
dataset.addSeries(series);

String str = "";
//listMaxAvgAmount = timeSeriesBean.getMaxAvgAmountForNDC(sNDC,(String)listPBM.get(i),sFromMonth,sFromYear,sToMonth,sToYear);
mapMaxAvgAmount = (Map)timeSeriesBean.getMaxAvgAmountForNDC(sNDC,(String)listPBM.get(i),sFromMonth,sFromYear,sToMonth,sToYear);
//System.out.println("in servlet>>>>>>>>>>>listMaxAvgAmount="+listMaxAvgAmount.size()+">>>>>>>>>>>"+mapMaxAvgAmount);
if(mapMaxAvgAmount.size()>0)
{
Set entries = mapMaxAvgAmount.entrySet();
Iterator iterator2 = entries.iterator();
while (iterator2.hasNext()) {
Map.Entry entry = (Map.Entry)iterator2.next();

String sMonthYear = (String)entry.getKey();

int iLenght = sMonthYear.length();

String sMonth = sMonthYear.substring(0 ,iLenght-4 );
String sYear = sMonthYear.substring(iLenght-4 ,iLenght );

System.out.println("In SErvlet>>>>>>>>>>sMonth==="+sMonth+"sYear++++"+sYear);
series.add(10,10);
// series.add( str, new Double((String) entry.getValue()).doubleValue());
series.add( new Double(sYear).doubleValue(), new Double((String) entry.getValue()).doubleValue());
// series.add(Integer.parseInt((String)entry.getKey()),Integer.parseInt((String)entry.getValue()));

}


}


}

}
} catch (Exception e) {

e.printStackTrace();
}
return ChartFactory.createXYLineChart(
"Time Series Chart",
"Time in Year",
"Amount",
dataset,
PlotOrientation.VERTICAL,
true,
true,
false);
}

Locked