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.DefaultCategoryDataset; 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 BarChart3DDemo2 extends ApplicationFrame { 65 66 77 82 public BarChart3DDemo2(String title) { 83 84 super(title); 85 86 DefaultCategoryDataset dataset = new DefaultCategoryDataset(); 88 dataset.addValue(23.0, "Series 1", "London"); 89 dataset.addValue(14.0, "Series 1", "New York"); 90 dataset.addValue(14.0, "Series 1", "Istanbul"); 91 dataset.addValue(14.0, "Series 1", "Cairo"); 92 dataset.addValue(13.0, "Series 2", "London"); 93 dataset.addValue(19.0, "Series 2", "New York"); 94 dataset.addValue(19.0, "Series 2", "Istanbul"); 95 dataset.addValue(19.0, "Series 2", "Cairo"); 96 dataset.addValue(7.0, "Series 3", "London"); 97 dataset.addValue(9.0, "Series 3", "New York"); 98 dataset.addValue(9.0, "Series 3", "Istanbul"); 99 dataset.addValue(9.0, "Series 3", "Cairo"); 100 101 JFreeChart chart = createChart(dataset); 102 103 ChartPanel chartPanel = new ChartPanel(chart); 105 chartPanel.setPreferredSize(new java.awt.Dimension (500, 270)); 106 setContentPane(chartPanel); 107 108 } 109 110 117 private JFreeChart createChart(CategoryDataset dataset) { 118 119 JFreeChart chart = ChartFactory.createBarChart3D( 120 "3D Bar Chart Demo 2", "Category", "Value", dataset, PlotOrientation.HORIZONTAL, true, true, false ); 129 130 CategoryPlot plot = chart.getCategoryPlot(); 131 plot.setForegroundAlpha(1.0f); 132 133 CategoryAxis axis = plot.getDomainAxis(); 134 CategoryLabelPosition position = new CategoryLabelPosition( 135 RectangleAnchor.LEFT, TextBlockAnchor.CENTER_LEFT, TextAnchor.CENTER_LEFT, 0.0 136 ); 137 axis.setLeftCategoryLabelPosition(position); 138 139 return chart; 140 141 } 142 143 148 public static void main(String [] args) { 149 150 BarChart3DDemo2 demo = new BarChart3DDemo2("3D Bar Chart Demo 2"); 151 demo.pack(); 152 RefineryUtilities.centerFrameOnScreen(demo); 153 demo.setVisible(true); 154 155 } 156 157 } 158 | Popular Tags |