学习JFreeChart(一)(2)

2008-02-23 10:01:04来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

, java.lang.Comparable rowKey, java.lang.Comparable columnKey) public void addValue(java.lang.Number value, java.lang.Comparable rowKey, java.lang.Comparable columnKey)

value - the value
rowKey - the row key
columnKey - the column key

参照前面的createDataset方法!

使用org.jfree.data.DatasetUtilities

org.jfree.data.DatasetUtilities class:

public static CategoryDataset createCategoryDataset(String rowKeyPrefix, String columnKeyPrefix, java.lang.Number[][] data)

public static CategoryDataset createCategoryDataset(String[] rowKeys, String[] columnKeys, double[][] data)

public static CategoryDataset createCategoryDataset(String rowKey, KeyedValues rowData)

rowKeyPrefix - the row key prefix.
columnKeyPrefix - the column key prefix.
rowKeys - the row keys.
columnKeys - the column keys.
data - the data.

   private CategoryDataset createDataset(){

      double[][] data = new double[][]{{1.0, 43.0, 35.0, 58.0, 54.0, 77.0, 71.0, 89.0}

         , {54.0, 75.0, 63.0, 83.0, 43.0, 46.0, 27.0, 13.0}

         , {41.0, 33.0, 22.0, 34.0, 62.0, 32.0, 42.0, 34.0}

      };

      return DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);

   }

第二步:創造JFreeChart

要用DataSet創造出一個JFreeChart類別,我們並不直接實體化出一個JFreeChart實體,而是使用ChartFactory類別裡面的方法。

ChartFactory class:

public static JFreeChart createBarChart(java.lang.String title,

                                        java.lang.String categoryAxisLabel,

                                        java.lang.String valueAxisLabel,

                                        CategoryDataset data,

                                        PlotOrientation orientation,

                                        boolean legend,

                                        boolean tooltips,

                                        boolean urls)

title - the chart title.
categoryAxisLabel - the label for the category axis.
valueAxisLabel - the label for the value axis data - the dataset for the chart.
orientation - the plot orientation (PlotOrientation.HORIZONTAL or PlotOrientation.VERTICAL).
legend - a flag specifying whether or not a legend is required.
tooltips - configure chart to generate tool tips?
urls - configure chart to generate URLs?

   private JFreeChart createChart(final CategoryDataset dataset){

      JFreeChart chart = ChartFactory.createBarChart(

         "Hello Bar Chart", // 题目
         "Category",   //行名称       
	"Value", // 列名称         
	dataset, // 数据         
	PlotOrientation.VERTICAL, // 横向,纵向         
	true, // 图例         
	true, // 柱状说明

         false // URLs?

         );

      return chart;

   }

第三步:修飾JFreeChart

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:JBuilder2005 JBoss-4.0.2RC1 J2SDK1.5 Log4j 开发Session Bean

下一篇:webshpere studio application developer 中 jndi 访问DATASOURC