1 40 41 package org.jfree.chart.demo; 42 43 import org.jfree.chart.ChartFactory; 44 import org.jfree.chart.ChartPanel; 45 import org.jfree.chart.JFreeChart; 46 import org.jfree.chart.axis.CategoryAxis; 47 import org.jfree.chart.axis.CategoryLabelPosition; 48 import org.jfree.chart.plot.CategoryPlot; 49 import org.jfree.chart.plot.PlotOrientation; 50 import org.jfree.data.CategoryDataset; 51 import org.jfree.data.DatasetUtilities; 52 import org.jfree.text.TextBlockAnchor; 53 import org.jfree.ui.ApplicationFrame; 54 import org.jfree.ui.RectangleAnchor; 55 import org.jfree.ui.RefineryUtilities; 56 import org.jfree.ui.TextAnchor; 57 58 64 public class BarChart3DDemo1 extends ApplicationFrame { 65 66 71 public BarChart3DDemo1(String title) { 72 73 super(title); 74 75 CategoryDataset dataset = createDataset(); 76 JFreeChart chart = createChart(dataset); 77 78 ChartPanel chartPanel = new ChartPanel(chart); 80 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 81 setContentPane(chartPanel); 82 83 } 84 85 90 private CategoryDataset createDataset() { 91 92 double[][] data = new double[][] 93 {{10.0, 4.0, 15.0, 14.0}, 94 {-5.0, -7.0, 14.0, -3.0}, 95 {6.0, 17.0, -12.0, 7.0}, 96 {7.0, 15.0, 11.0, 0.0}, 97 {-8.0, -6.0, 10.0, -9.0}, 98 {9.0, 8.0, 0.0, 6.0}, 99 {-10.0, 9.0, 7.0, 7.0}, 100 {11.0, 13.0, 9.0, 9.0}, 101 {-3.0, 7.0, 11.0, -10.0}}; 102 103 return DatasetUtilities.createCategoryDataset("Series ", "Category ", data); 104 105 } 106 107 114 private JFreeChart createChart(CategoryDataset dataset) { 115 116 JFreeChart chart = ChartFactory.createBarChart3D( 117 "3D Bar Chart Demo", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false ); 126 127 CategoryPlot plot = chart.getCategoryPlot(); 128 CategoryAxis axis = plot.getDomainAxis(); 129 CategoryLabelPosition position = new CategoryLabelPosition( 130 RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0 131 ); 132 axis.setBottomCategoryLabelPosition(position); 133 134 return chart; 135 136 } 137 138 149 154 public static void main(String [] args) { 155 156 BarChart3DDemo1 demo = new BarChart3DDemo1("3D Bar Chart Demo 1"); 157 demo.pack(); 158 RefineryUtilities.centerFrameOnScreen(demo); 159 demo.setVisible(true); 160 161 } 162 163 } 164 | Popular Tags |