日期:2014-05-19 浏览次数:20793 次
import java.awt.*; import javax.swing.JPanel; import org.jfree.chart.*; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.labels.*; import org.jfree.chart.plot.*; import org.jfree.chart.renderer.category.BarRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.jfree.ui.*; public class BarChartDemo3 extends ApplicationFrame { static class CustomRenderer extends BarRenderer { private Paint colors[]; public Paint getItemPaint(int i, int j) { return colors[j % colors.length]; } public CustomRenderer(Paint apaint[]) { colors = apaint; } } public BarChartDemo3(String s) { super(s); CategoryDataset categorydataset = createDataset(); JFreeChart jfreechart = createChart(categorydataset); ChartPanel chartpanel = new ChartPanel(jfreechart); chartpanel.setPreferredSize(new Dimension(500, 270)); setContentPane(chartpanel); } private static CategoryDataset createDataset() { double ad[][] = { { 4D, 3D, -2D, 3D, 6D } }; return DatasetUtilities.createCategoryDataset("Series ", "Category ", ad); } private static JFreeChart createChart(CategoryDataset categorydataset) { JFreeChart ){ wit