?? combinedcategoryplotdemo2.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ------------------------------
* CombinedCategoryPlotDemo2.java
* ------------------------------
* (C) Copyright 2003, by Object Refinery Limited.
*
* Original Author: David Gilbert (for Object Refinery Limited).
* Contributor(s): -;
*
* $Id: CombinedCategoryPlotDemo2.java,v 1.6 2003/07/23 15:17:44 mungady Exp $
*
* Changes
* -------
* 16-May-2003 : Version 1 (DG);
*
*/
package org.jfree.chart.demo;
import java.awt.Font;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.Legend;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.CombinedRangeCategoryPlot;
import org.jfree.chart.renderer.BarRenderer;
import org.jfree.chart.renderer.LineAndShapeRenderer;
import org.jfree.data.CategoryDataset;
import org.jfree.data.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
/**
* A demo for the {@link CombinedRangeCategoryPlot} class.
*
* @author David Gilbert
*/
public class CombinedCategoryPlotDemo2 extends ApplicationFrame {
/**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public CombinedCategoryPlotDemo2(String title) {
super(title);
// add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(createChart());
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}
/**
* Creates a dataset.
*
* @return A dataset.
*/
public CategoryDataset createDataset1() {
DefaultCategoryDataset result = new DefaultCategoryDataset();
// row keys...
String series1 = "First";
String series2 = "Second";
// column keys...
String type1 = "Type 1";
String type2 = "Type 2";
String type3 = "Type 3";
String type4 = "Type 4";
String type5 = "Type 5";
String type6 = "Type 6";
String type7 = "Type 7";
String type8 = "Type 8";
result.addValue(1.0, series1, type1);
result.addValue(4.0, series1, type2);
result.addValue(3.0, series1, type3);
result.addValue(5.0, series1, type4);
result.addValue(5.0, series1, type5);
result.addValue(7.0, series1, type6);
result.addValue(7.0, series1, type7);
result.addValue(8.0, series1, type8);
result.addValue(5.0, series2, type1);
result.addValue(7.0, series2, type2);
result.addValue(6.0, series2, type3);
result.addValue(8.0, series2, type4);
result.addValue(4.0, series2, type5);
result.addValue(4.0, series2, type6);
result.addValue(2.0, series2, type7);
result.addValue(1.0, series2, type8);
return result;
}
/**
* Creates a dataset.
*
* @return A dataset.
*/
public CategoryDataset createDataset2() {
DefaultCategoryDataset result = new DefaultCategoryDataset();
// row keys...
String series1 = "Third";
String series2 = "Fourth";
// column keys...
String sector1 = "Sector 1";
String sector2 = "Sector 2";
String sector3 = "Sector 3";
String sector4 = "Sector 4";
result.addValue(11.0, series1, sector1);
result.addValue(14.0, series1, sector2);
result.addValue(13.0, series1, sector3);
result.addValue(15.0, series1, sector4);
result.addValue(15.0, series2, sector1);
result.addValue(17.0, series2, sector2);
result.addValue(16.0, series2, sector3);
result.addValue(18.0, series2, sector4);
return result;
}
/**
* Creates a chart.
*
* @return A chart.
*/
private JFreeChart createChart() {
CategoryDataset dataset1 = createDataset1();
CategoryAxis domainAxis1 = new CategoryAxis("Class 1");
LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
renderer1.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
CategoryPlot subplot1 = new CategoryPlot(dataset1, domainAxis1, null, renderer1);
subplot1.setDomainGridlinesVisible(true);
subplot1.getDomainAxis().setVerticalCategoryLabels(true);
CategoryDataset dataset2 = createDataset2();
CategoryAxis domainAxis2 = new CategoryAxis("Class 2");
BarRenderer renderer2 = new BarRenderer();
renderer2.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
CategoryPlot subplot2 = new CategoryPlot(dataset2, domainAxis2, null, renderer2);
subplot2.setDomainGridlinesVisible(true);
subplot2.getDomainAxis().setVerticalCategoryLabels(true);
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
);
result.getLegend().setAnchor(Legend.SOUTH);
return result;
}
/**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) {
String title = "Combined Category Plot Demo 2";
CombinedCategoryPlotDemo2 demo = new CombinedCategoryPlotDemo2(title);
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -