Chinaunix首页 | 论坛 | 博客
  • 博客访问: 203158
  • 博文数量: 73
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 750
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-13 18:32
文章分类

全部博文(73)

文章存档

2009年(1)

2008年(72)

我的朋友

分类: Java

2008-04-05 16:14:11

Introduction
  JFreeChart supports the use of multiple axes and datasets in the CategoryPlot and XYPlot classes. You can use this feature to display two or more datasets on a single chart, while making allowance for the fact that the datasets may contain data of vastly different magnitudes.
  Refer to 1.bmp.
 
Typical charts constructed with JFreeChart use a plot that has a single dataset, a single renderer, a single domain axis and a single range axis. However, it is possible to add multiple datasets, renderers and axes to a plot.

Steps
  Create a Chart
  To create a chart with multiple axes, datasets, and renderers, you should first create a regular chart (for example, using the ChartFactory class). You can use any chart that is constructed using a CategoryPlot or an XYPlot. In the example, a time series chart is created as follows:
  XYDataset dataset1 = createDataset(
    "Series 1", 100.0,new Minute(), 200);

  JFreeChart chart = ChartFactory.createTimeSeriesChart(
    "Multiple Axis Demo 1",
    "Time of Day",
    "Primary Range Axis",
    dataset1,
    true,
    true,
    false
   );
  Adding an Additional Axis
  To add an additional axis to a plot, you can use the setRangeAxis() method:
  NumberAxis axis2 = new NumberAxis("Range Axis 2");
  plot.setRangeAxis(1, axis2);
  plot.setRangeAxisLocation(1,
    AxisLocation.BOTTOM OR   RIGHT);
  Note that an index of 1 (one) has been used—you can add as many additional axes as you require, by incrementing the index each time you add a new axis.
  The setRangeAxisLocation() method allows you to specify where the axis will appear on the chart, using the AxisLocation class.
  In the example, BOTTOM OR RIGHT is specified, which means (for a range axis) on the right if the plot has a vertical orientation, or at the bottom if the plot has
a horizontal orientation.
  At this point, no additional dataset has been added to the chart, so if you were to display the chart you would see the additional axis, but it would have no data plotted against it.
 
  Adding an Additional Dataset

  To add an additional dataset to a plot, use the setDataset() method:
  XYDataset dataset2 = ... // up to you
  plot.setDataset(1, dataset2);
  Combine the newly-added axis and dataset:
  By default, the dataset will be plotted against the primary range axis. To have the dataset plotted against a different axis, use the mapDatasetToDomainAxis() and mapDatasetToRangeAxis() methods.
  These methods accept two arguments, the first is the index of the dataset, and the second is the index of the axis.

  Adding an Additional Renderer
  When you add an additional dataset, usually it makes sense to add an additional renderer to go with the dataset. Use the setRenderer() method:
  XYItemRenderer renderer2 = ... // up to you
  plot.setRenderer(1, renderer2);
  The index (1 in this case) should correspond to the index of the dataset added previously.
  #It's almost a must to add a new renderer,when you add a new dataset.
  Note: if you don’t specify an additional renderer, the primary renderer will be used instead. In that case, the series colors will be shared between the primary dataset and the additional dataset.
 

文件:1.zip
大小:36KB
下载:下载


阅读(1592) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~