免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1302 | 回复: 0
打印 上一主题 下一主题

jfreechart之旅 Multiple Axes and Datasets [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-05 16:14 |只看该作者 |倒序浏览
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 hasa 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
        下载:
下载
       


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/63463/showart_518003.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP