1 37 38 package org.jfree.chart.demo; 39 40 import org.jfree.chart.ChartFactory; 41 import org.jfree.chart.ChartPanel; 42 import org.jfree.chart.JFreeChart; 43 import org.jfree.chart.axis.CategoryAxis; 44 import org.jfree.chart.axis.CategoryLabelPosition; 45 import org.jfree.chart.plot.CategoryPlot; 46 import org.jfree.chart.plot.PlotOrientation; 47 import org.jfree.chart.renderer.BarRenderer; 48 import org.jfree.chart.renderer.CategoryItemRenderer; 49 import org.jfree.data.CategoryDataset; 50 import org.jfree.data.DefaultCategoryDataset; 51 import org.jfree.text.TextBlockAnchor; 52 import org.jfree.ui.ApplicationFrame; 53 import org.jfree.ui.RectangleAnchor; 54 import org.jfree.ui.RefineryUtilities; 55 import org.jfree.ui.TextAnchor; 56 57 62 public class BarChart3DDemo3 extends ApplicationFrame { 63 64 69 public BarChart3DDemo3(String title) { 70 71 super(title); 72 73 CategoryDataset dataset = createDataset(); 74 JFreeChart chart = createChart(dataset); 75 ChartPanel chartPanel = new ChartPanel(chart); 76 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 77 setContentPane(chartPanel); 78 79 } 80 81 92 97 private CategoryDataset createDataset() { 98 99 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 100 dataset.addValue(25.0, "Series 1", "Category 1"); 101 dataset.addValue(34.0, "Series 1", "Category 2"); 102 dataset.addValue(19.0, "Series 2", "Category 1"); 103 dataset.addValue(29.0, "Series 2", "Category 2"); 104 dataset.addValue(41.0, "Series 3", "Category 1"); 105 dataset.addValue(33.0, "Series 3", "Category 2"); 106 return dataset; 107 108 } 109 110 117 private JFreeChart createChart(CategoryDataset dataset) { 118 119 JFreeChart chart = ChartFactory.createBarChart3D( 120 "3D Bar Chart Demo", "Category", "Value", dataset, PlotOrientation.VERTICAL, true, true, false ); 129 130 CategoryPlot plot = chart.getCategoryPlot(); 131 CategoryAxis axis = plot.getDomainAxis(); 132 CategoryLabelPosition position = new CategoryLabelPosition( 133 RectangleAnchor.TOP, TextBlockAnchor.TOP_RIGHT, TextAnchor.TOP_RIGHT, -Math.PI / 8.0 134 ); 135 axis.setBottomCategoryLabelPosition(position); 136 137 CategoryItemRenderer renderer = plot.getRenderer(); 138 renderer.setItemLabelsVisible(true); 139 BarRenderer r = (BarRenderer) renderer; 140 r.setMaxBarWidth(0.05); 141 142 return chart; 143 144 } 145 146 147 152 public static void main(String [] args) { 153 154 BarChart3DDemo3 demo = new BarChart3DDemo3("3D Bar Chart Demo 3"); 155 demo.pack(); 156 RefineryUtilities.centerFrameOnScreen(demo); 157 demo.setVisible(true); 158 159 } 160 161 } 162 | Popular Tags |