助力软件开发企业降本增效 PHP / java源码系统,只需一次付费,代码终身使用! 广告
## 14.3 组合Y种类图区 ### 14.3.1 概述 一个组合Y种类图区就是一个图区显示两个或两个以上的子图区(CategoryPlot实例),共享Y轴。如果14.2. ![](img/jfc88251.png) 图14.2 组合Y种类图区 该图表可以水平显示也可以垂直显示(本例是垂直显示)。 ### 14.3.2 构建图表 实例演示了如何创建该类型图表。关键的步骤是创建一个实例,然后添加两个子图区: ``` ValueAxis rangeAxis = new NumberAxis("Value");``` CombinedRangeCategoryPlot plot = new CombinedRangeCategoryPlot(rangeAxis); plot.add(subplot1, 3); plot.add(subplot2, 2); JFreeChart result = new JFreeChart("Combined Range Category Plot Demo", new Font("SansSerif", Font.BOLD, 12), plot, true); ``` 注意添加的子图区subplot1什么码值是3而子图区subplot2码值是2呢。这是因为该值控制这两个子图区分配的空间大小。 子图区是CategoryPlot实例,将Y轴设置为null。例如,在本实例演示的代码如下: ``` CategoryDataset dataset1 = createDataset1(); CategoryAxis domainAxis1 = new CategoryAxis("Class 1"); domainAxis1.setCategoryLabelPositions(CategoryLabelPositions.UP 45); domainAxis1.setMaxCategoryLabelWidthRatio(5.0f); LineAndShapeRenderer renderer1 = new LineAndShapeRenderer(); renderer1.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot1 = new CategoryPlot(dataset1, domainAxis1, null, renderer1); subplot1.setDomainGridlinesVisible(true); CategoryDataset dataset2 = createDataset2(); CategoryAxis domainAxis2 = new CategoryAxis("Class 2"); domainAxis2.setCategoryLabelPositions(CategoryLabelPositions.UP 45); domainAxis2.setMaxCategoryLabelWidthRatio(5.0f); BarRenderer renderer2 = new BarRenderer(); renderer2.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator()); CategoryPlot subplot2 = new CategoryPlot(dataset2, domainAxis2, null, renderer2); subplot2.setDomainGridlinesVisible(true); ```