电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

实例编程:JFreechart 的一些用法


发布日期:2018/10/16
 

public abstract class AbstractStatistic implements Statistic {

/**

* 创建统计图形

*

* @param columnKeys

* 关键字数组

* @param data

* 数据数组

* @param title

* 标题

* @param session

* @param rowKeys

* 行关键字

* @param showType

* @return

*/

public String createStatisticImg(String[] columnKeys double[][] data

String title HttpSession session String[] rowKeys String showType) {

try {

JFreeChart chart = null;

if(showTypeequals()){

chart = createBarChartD(datacolumnKeysrowKeystitle);

}

if(showTypeequals()){

chart = createLineChart(datacolumnKeysrowKeystitle);

}

if(showTypeequals()){

chart = createAreaChart(datacolumnKeysrowKeystitle);

}

if(showTypeequals()){

chart = createLineChartD(data columnKeys rowKeys title);

}

String filename = ServletUtilitiessaveChartAsPNG(chart

null session);

return filename;

} catch (IOException e) {

// TODO Autogenerated catch block

eprintStackTrace();

}

return ;

}

public JFreeChart createBarChartD(double[][] data String[] columnKeys String[] rowKeysString title){

CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

rowKeys columnKeys data);

JFreeChart chart = ChartFactorycreateBarChartD(title// 分布与对比图

null dataset PlotOrientationVERTICAL true false

false);

chartsetBackgroundPaint(ColorWHITE);// 设置整张图片背景色

CategoryPlot plot = chartgetCategoryPlot();

plotsetBackgroundPaint(Colorgray);// 设置图形区域背景色

// 设置是否显示垂直网格线

plotsetDomainGridlinesVisible(true);

// 设置是否显示水平网格线

plotsetRangeGridlinesVisible(true);

CategoryAxis domainAxis = plotgetDomainAxis();

/*设置X轴标题的倾斜程度*/

domainAxissetCategoryLabelPositions(CategoryLabelPositionsSTANDARD);

domainAxissetMaximumCategoryLabelLines();

domainAxissetTickLabelFont(new Font(黑体 FontPLAIN ));

plotsetDomainAxis(domainAxis);

ValueAxis rangeAxis = plotgetRangeAxis();

// 设置最高的一个 Item 与图片顶端的距离

rangeAxissetUpperMargin();

// 设置最低的一个 Item 与图片底端的距离

rangeAxissetLowerMargin();

plotsetRangeAxis(rangeAxis);

BarRendererD renderer = new BarRendererD();

renderersetBaseOutlinePaint(ColorBLACK);

// 设置 Wall 的颜色

renderersetWallPaint(Colorgray);

// 设置每种柱的颜色

renderersetSeriesPaint( new Color( ));

renderersetSeriesPaint( new Color( ));

renderersetSeriesPaint( new Color( ));

// 置每种柱的 Outline 颜色

renderersetSeriesOutlinePaint( ColorBLACK);

renderersetSeriesOutlinePaint( ColorBLACK);

renderersetSeriesOutlinePaint( ColorBLACK);

// 设置每个地区所包含的平行柱的之间距离

renderersetItemMargin();

// 显示每个柱的数值并修改该数值的字体属性

// renderersetSeriesItemLabelGenerator(new

// StandardCategoryItemLabelGenerator(##%javatextNumberFormatgetPercentInstance()));

renderer

setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

renderersetItemLabelFont(new Font(黑体 FontPLAIN ));

renderersetItemLabelsVisible(true);

// 设置标签显示位置不加这句将显示在柱体内

renderersetPositiveItemLabelPosition(new ItemLabelPosition(

ItemLabelAnchorOUTSIDE TextAnchorBOTTOM_CENTER));

plotsetRenderer(renderer);

// 设置柱的透明度

plotsetForegroundAlpha(f);

// 设置地区销量的显示位置

plotsetDomainAxisLocation(AxisLocationBOTTOM_OR_LEFT);

plotsetRangeAxisLocation(AxisLocationBOTTOM_OR_LEFT);

return chart;

}

public JFreeChart createLineChart(double[][] data String[] columnKeys String[] rowKeysString title){

CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

rowKeys columnKeys data);

JFreeChart chart = ChartFactorycreateLineChart(title// 区域分布与对比图

null dataset PlotOrientationVERTICAL true false

false);

CategoryPlot plot = chartgetCategoryPlot();

CategoryAxis domainAxis = plotgetDomainAxis();

/*设置X轴标题的倾斜程度*/

domainAxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

domainAxissetTickLabelFont(new Font(黑体 FontPLAIN ));

return chart;

}

public JFreeChart createLineChartD(double[][] data String[] columnKeys String[] rowKeysString title){

CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

rowKeys columnKeys data);

JFreeChart chart = ChartFactorycreateLineChartD(title// 区域分布与对比图

null dataset PlotOrientationVERTICAL true false

false);

CategoryPlot plot = chartgetCategoryPlot();

CategoryAxis domainAxis = plotgetDomainAxis();

/*设置X轴标题的倾斜程度*/

domainAxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

domainAxissetTickLabelFont(new Font(黑体 FontPLAIN ));

return chart;

}

public JFreeChart createAreaChart(double[][] data String[] columnKeys String[] rowKeysString title){

CategoryDataset dataset = DatasetUtilitiescreateCategoryDataset(

rowKeys columnKeys data);

JFreeChart chart = ChartFactorycreateAreaChart(title 统计时间 统计数量 dataset PlotOrientationVERTICAL true true false);

chartsetBackgroundPaint(Colorwhite);

CategoryPlot categoryplot = (CategoryPlot)chartgetPlot();

categoryplotsetForegroundAlpha(F);

categoryplotsetAxisOffset(new RectangleInsets(D D D D));

categoryplotsetBackgroundPaint(ColorlightGray);

categoryplotsetDomainGridlinesVisible(true);

categoryplotsetDomainGridlinePaint(Colorwhite);

categoryplotsetRangeGridlinesVisible(true);

categoryplotsetRangeGridlinePaint(Colorwhite);

CategoryAxis categoryaxis = categoryplotgetDomainAxis();

categoryaxissetCategoryLabelPositions(CategoryLabelPositionsUP_);

categoryaxissetLowerMargin(D);

categoryaxissetUpperMargin(D);

categoryaxisaddCategoryLabelToolTip(Type The first type);

categoryaxisaddCategoryLabelToolTip(Type The second type);

categoryaxisaddCategoryLabelToolTip(Type The third type);

NumberAxis numberaxis = (NumberAxis)categoryplotgetRangeAxis();

numberaxissetStandardTickUnits(NumberAxiscreateIntegerTickUnits());

numberaxissetLabelAngle(D);

return chart;

上一篇:主类型的过载

下一篇:分析和设计