- 论坛徽章:
- 0
|
Introduction
JFreeChart supports combined charts via several plot classes that can manage any number of subplots:
• CombinedDomainCategoryPlot / CombinedRangeCategoryPlot;• CombinedDomainXYPlot / CombinedRangeXYPlot;
Combined Domain Category Plot
A combined domain category plot is a plot that displays two or more subplots (instances of CategoryPlot)
that share a common domain axis. Each subplot maintains its own range axis.
Refer to 1.bmp
Constructing the Chart
The key step is the creation of a CombinedDomainCategoryPlot instance, to which subplots are added:
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 );
Notice how subplot1 has been added with a weight of 2 (the second argument in the add() method, while subplot2 has been added with a weight of 1. This controls the amount of space allocated to each plot. The subplots are regular CategoryPlot instances that have had their domain axis set to 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);
Combined Range Category Plot
A combined range category plot is a plot that displays two or more subplots (instances of CategoryPlot) that share a common range axis. Each subplot maintains its own domain axis.
Refer to 2.bmp
Constructing the Chart
The key step is the creation of a CombinedRangeCategoryPlot instance, to which subplots
are added:
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
);
The subplots are regular CategoryPlot instances that have had their range axis set to 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);
Combined Domain XY Plot
A combined domain XY plot is a plot that displays two or more subplots (instances of XYPlot) thatshare a common domain axis. Each subplot maintains its own range axis.
Refer to 3.bmp.
The key step is the creation of a CombinedDomainXYPlot instance, to which subplots are added:
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
);
The subplots are regular XYPlot instances that have had their domain axis set to 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);
Combined Range XY Plot
A combined range XY plot is a plot that displays two or more subplots (instances of XYPlot) that share a common range axis. Each subplot maintains its own domain axis.
Refer to 4.bmp
// create the plot...
CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis("Value")); plot.add(subplot1, 1); plot.add(subplot2, 1); return new JFreeChart( "Combined (Range) XY Plot", JFreeChart.DEFAULT TITLE FONT, plot, true );
// 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);
![]()
文件:1.zip
大小:68KB
下载:
下载
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/63463/showart_518460.html |
|