前言

JFreeChart支持几个图区类(可以管理着多个子类)组合而成的图表。 图区类可以管理几个子类:

CombinedDomainCategoryPlot / CombinedRangeCategoryPlot
CombinedDomainXYPlot / CombinedRangeXYPlot ;

本文主要讲解四种组合图:

  • 组合X种类图区(Combined Domain Category Plot)
  • 组合Y种类图区(Combined Range Category Plot)
  • 组合X-XY图区(Combined Domain XY Plot)
  • 组合Y-XY图区(Combined Range XY Plot)

一.组合X种类图区(Combined Domain Category Plot)

组合主域种类图区就是在一个图区上显示两个或者多个子图区(CategoryPlot实例),共享一个X轴的图区。 每个子图区维护自己的Y轴。 如图所示

显示图表可以是水平的,也可以是垂直方向的——实例演示的是垂直的图表.

创建图表的核心:
提供了一个很好的例子,演示如何创建该图表的类型。 关键的步骤是创建CombinedDomainCategoryPlot实例,然后添加两个子图区:

CategoryAxis domainAxis = new CategoryAxis("Category");
CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot(domainAxis);
plot.add(subplot1, 2);
plot.add(subplot2, 1);
JFreeChart result = new JFreeChart(
"Combined Domain Category Plot Demo",
new Font("SansSerif", Font.BOLD, 12),
plot,
true
);

注意:

  • 我们subplot1添加码值时是2(方法add()的第二个参数),而subplot1添加的是1呢?因为这控制着分配给各个图区的空间大小。

  • 子图区的CategoryPlot实例对象将它们的X轴设置为null,

例如在演示的实例中,代码如下:

CategoryDataset dataset1 = createDataset1();
NumberAxis rangeAxis1 = new NumberAxis("Value");
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot1 = new CategoryPlot(dataset1, null, rangeAxis1, renderer1);
subplot1.setDomainGridlinesVisible(true);CategoryDataset dataset2 = createDataset2();
NumberAxis rangeAxis2 = new NumberAxis("Value");
rangeAxis2.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot2 = new CategoryPlot(dataset2, null, rangeAxis2, renderer2);
subplot2.setDomainGridlinesVisible(true);

二.组合Y种类图区(Combined Range Category Plot)

基本与组合X种类图区(Combined Domain Category Plot)一致.
一个组合Y种类图区就是一个图区显示两个或两个以上的子图区(CategoryPlot实例),共享Y轴。该图表可以水平显示也可以垂直显示(本例是垂直显示)。

关键的步骤是创建一个实例,然后添加两个子图区(Plot),添加的子图区subplot1什么数值是3而子图区subplot2码值是2呢。这是因为该值控制这两个子图区分配的空间大小.子图区是CategoryPlot实例,将Y轴设置为null。 在本实例演示的代码如下:

CategoryDataset dataset1 = createDataset1();
CategoryAxis categoryAxis1 = new CategoryAxis("Class 1");
categoryAxis1.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryAxis1.setMaximumCategoryLabelWidthRatio(5.0F);
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot1 = new CategoryPlot(dataset1, categoryAxis1, null, renderer1);
subplot1.setDomainGridlinesVisible(true);CategoryDataset dataset2 = createDataset2();
CategoryAxis categoryAxis2 = new CategoryAxis("Class 2");
categoryAxis2.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
categoryAxis2.setMaximumCategoryLabelWidthRatio(5.0F);
BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
CategoryPlot subplot2 = new CategoryPlot(dataset2, categoryAxis2, null, renderer2);
subplot2.setDomainGridlinesVisible(true);
NumberAxis rangeAxis2 = new NumberAxis("Value");CombinedRangeCategoryPlot combinedPlot = new CombinedRangeCategoryPlot(rangeAxis2);
combinedPlot.setRangePannable(true);
combinedPlot.add(subplot1, 3);
combinedPlot.add(subplot2, 2);
combinedPlot.setOrientation(PlotOrientation.HORIZONTAL);JFreeChart chart = new JFreeChart("Combined Range Category Plot Demo", new Font("SansSerif", 1, 12), combinedPlot, true);
ChartUtilities.applyCurrentTheme(chart);

三.组合X-XY图区(Combined Domain XY Plot)

组合X-XY图区就是一个图区显示两个或者多个子图区(XYPlot实例),共享一个X轴。 每一个子图区维护自己的Y轴。 如下图所示:

创建该图表一个,关键的步骤是创建一个实例CombinedDomainXYPlot,并在该实例上添加两个子图区:

CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
plot.setGap(10.0);
plot.add(subplot1, 1);
plot.add(subplot2, 1);
plot.setOrientation(PlotOrientation.VERTICAL);
return new JFreeChart("CombinedDomainXYPlot Demo",JFreeChart.DEFAULT_TITLE_FONT, plot, true
);

注意两个图区的码值为什么都是1呢?因为该数值控制着每个图区分配的空间大小。子图区是XYPlot实例,将自己的X轴设置为null。 例如,下面的代码演示了这个特征:

XYDataset data1 = createDataset1();
XYItemRenderer renderer1 = new StandardXYItemRenderer();
NumberAxis rangeAxis1 = new NumberAxis("Range 1");
XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
subplot1.setRangeAxisLocation(AxisLocation.BOTTOM OR LEFT);
XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0, 10000.0);
annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
annotation.setRotationAngle(Math.PI / 4.0);
subplot1.addAnnotation(annotation);// create subplot 2...
XYDataset data2 = createDataset2();
XYItemRenderer renderer2 = new StandardXYItemRenderer();
NumberAxis rangeAxis2 = new NumberAxis("Range 2");
rangeAxis2.setAutoRangeIncludesZero(false);
XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
subplot2.setRangeAxisLocation(AxisLocation.TOP OR LEFT);

四.组合Y-XY图区(Combined Range XY Plot)

组合Y-XY图区就是一个图区显示两个或者多个子图区(XYPlot实例),共享一个Y轴。 每一个子图区维护自己的X轴。 如下图所示
图区可能水平显示也可能垂直显示(本例子中垂直显示)。

上图演示了如何创建该类型的图表。 关键的步骤是创建一个实例CombinedRangeXYPlot,并在该实例上添加两个子图区:

// create the plot...
CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Value"));
plot.add(xyplot, 1);
plot.add(xyplot_0_, 1);
return new JFreeChart("Combined (Range) XY Plot",JFreeChart.DEFAULT_TITLE_FONT, plot, true
)

注意两个图区的码值为什么都是1呢?因为该数值控制着每个图区分配的空间大小。子图区是XYPlot实例,将自己的X轴设置为null。 例如,下面的代码演示了这个特征:

// create subplot 1...
IntervalXYDataset data1 = createDataset1();
XYItemRenderer renderer1 = new XYBarRenderer(0.20);
renderer1.setToolTipGenerator(new StandardXYToolTipGenerator(new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0")
)
);
XYPlot subplot1 = new XYPlot(data1, new DateAxis("Date"), null, renderer1);// create subplot 2...
XYDataset data2 = createDataset2();
XYItemRenderer renderer2 = new StandardXYItemRenderer();
renderer2.setToolTipGenerator(new StandardXYToolTipGenerator(new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0,000.0"))
);
XYPlot subplot2 = new XYPlot(data2, new DateAxis("Date"), null, renderer2);

JFreeChart| JFreeChart组合图表(Combined Charts)相关推荐

  1. 【JFreeChart】JFreeChart—输出组合图表

    组合图表(Combined Chart)可以组合不同的图形,例如柱状图和折线图等,通常显示股票的图,比如上方式股票价格,下方是成交量. 实现代码: CombinedChartServlet.java ...

  2. jfreechart实现动态图表

    1.生成图形报表时一般使用制图工厂ChartFatory类进行创建,只有创建制图对象jfreechart后才能生成实际图片,然后可以设置图片边界,字体等属性 2.数据集合是用来装载绘图表所需要的数据集 ...

  3. Pyecharts组合图表复用渲染模块实现方法

    Pyecharts 组合图表 复用更新数据实现方法记录[一定要看说明文档] 2020-11-04 DraggablePageLayout 布局 page = Page(layout=Page.Drag ...

  4. pyecharts可视化展示之仪表盘、词云、组合图表、桑基图学习

    一.绘制仪表盘 通过Gauge绘制仪表盘 #仪表盘 from pyecharts import options as opts from pyecharts.charts import Gauge,P ...

  5. Science:组合图表绘制

    写在前面 有些事情做了很痛苦,但是不做更难受.比如今天谈到的这件事情,我花了一天加一个晚上时间才写了一个这个功能:Science组合图表的实现.这部分一共写了三个函数,一个门特尔检验,一个ggplot ...

  6. 最终版本Science级组合图表绘制

    简介 ggcor 是厚哥最近的作品,功能完全代替了science组合图表绘制.这里我也为大家带力实战教程,总体来说厚哥这个ggcor包用起来还是挺方便的,将许多功能简化,为我们提供了一个很好的入门机会 ...

  7. R语言单变量分析实战:汇总统计(Summary Statistics)、频率表(Frequency Table)、图表(charts: boxplot、histogram、density)

    R语言单变量分析实战:汇总统计(Summary Statistics).频率表(Frequency Table).图表(charts: boxplot.histogram.density) 目录

  8. science图表_Science:组合图表绘制

    写在前面 有些事情做了很痛苦,但是不做更难受.比如今天谈到的这件事情,我花了一天加一个晚上时间才写了一个这个功能:Science组合图表的实现.这部分一共写了三个函数,一个门特尔检验,一个ggplot ...

  9. r中gglot怎么组合多张图_最终版本Science级组合图表绘制

    简介 ggcor 是 厚哥最近的作品,功能完全代替了前两次的你终于可以做这张图和重大升级的两个science组合图表绘制.这里我也为大家带肋实战教程,总体来说厚哥这个ggcor包用起来还是挺方便的,将 ...

最新文章

  1. 快讯 | 老黄啊,特斯拉背着你找AMD了,咱可不能给他降价
  2. mysql 4G内存配置表
  3. java 取绝对值_Java实现一致性哈希算法,并搭建环境测试其负载均衡特性
  4. IE浏览器上传文件时本地路径变成”C:\fakepath\”的问题
  5. [Embeding-3]综述:词嵌入以及与分布式语义模型的关联
  6. 理论基础 —— 索引 —— 分块索引
  7. si4438 与 si4432通讯
  8. CSNN: An Augmented Spiking based Framework with Perceptron-Inception
  9. 在虚拟机环境(CentOS7系统)下将kubernetes中部署服务成功,但在虚拟机外部无法访问到服务...
  10. 实战Vue:ToDoList
  11. 完美数简介及算法分析
  12. SpringCloud:Gateway网关配置及使用
  13. 途家2019校招笔试 1 求最大公约数和最小公倍数
  14. 家用千兆路由器排行榜前十名_千兆家用路由器品牌推荐,总有一款适合你!
  15. 量化:常见策略指标合集
  16. linux NM 命令使用介绍
  17. ●「.|貓」erPhotoshop滤镜巧制超级美女插画效果
  18. 探究ESP32S【第六天】——接入米家(插曲)
  19. oracle的闪存_ORACLEFS1-2闪存存储系统.PDF
  20. 友盟分享 微博 c8998文件不存在

热门文章

  1. c语言社团管理系统实验报告,C语言课程设计大学社团管理系统
  2. javascript操作select元素一例
  3. hyperf使用curl产生的超时问题
  4. html+css day1 如何用Mac创建html文件
  5. linux系统如何安装mtk驱动程序,模块编译问题 给MTK芯片的wifi网卡编译linux驱动 系统是mint...
  6. ​ClinChoice昆翎完成收购北京岐黄;武田与红十字会达成合作;诺诚健华奥布替尼获美国FDA突破性疗法认定 | 医药健闻...
  7. 产品运营:如何激活沉默用户
  8. vpr文件转换flac_vpr文件格式怎么转换,划重点了
  9. Pointnet语义分割任务S3DIS数据集上的注意点
  10. Carmack(卡马克)传奇的3D引擎开源代码