JFreeChart中图象的一些设置

JFreeChart中图象的一些设置,见下边的例子:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import = "org.jfree.chart.ChartFactory,
java.text.SimpleDateFormat,
org.jfree.chart.axis.DateTickUnit,
org.jfree.chart.JFreeChart,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.chart.title.TextTitle,
org.jfree.data.time.TimeSeries,
org.jfree.data.time.Month,
org.jfree.data.time.TimeSeriesCollection,
java.awt.Font,
org.jfree.chart.plot.XYPlot,
java.awt.Color,
org.jfree.chart.renderer.xy.XYLineAndShapeRenderer,
org.jfree.chart.axis.DateAxis"
%>
<%
//访问量统计时间线
TimeSeries timeSeries = new TimeSeries("阿蜜果blog访问量统计", Month.class);
//时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();

//构造数据集合
timeSeries.add(new Month(1, 2007), 11200);
timeSeries.add(new Month(2, 2007), 9000);
timeSeries.add(new Month(3, 2007), 6200);
timeSeries.add(new Month(4, 2007), 8200);
timeSeries.add(new Month(5, 2007), 8200);
timeSeries.add(new Month(6, 2007), 12200);
timeSeries.add(new Month(7, 2007), 13200);
timeSeries.add(new Month(8, 2007), 8300);
timeSeries.add(new Month(9, 2007), 12400);
timeSeries.add(new Month(10, 2007), 12500);
timeSeries.add(new Month(11, 2007), 13600);
timeSeries.add(new Month(12, 2007), 12500);

TimeSeries timeSeries1 = new TimeSeries("阿蜜果blog访问量统计1", Month.class);

//构造数据集合
timeSeries1.add(new Month(1, 2007), 1120);
timeSeries1.add(new Month(2, 2007), 900);
timeSeries1.add(new Month(3, 2007), 620);
timeSeries1.add(new Month(4, 2007), 820);
timeSeries1.add(new Month(5, 2007), 820);
timeSeries1.add(new Month(6, 2007), 1220);
timeSeries1.add(new Month(7, 2007), 1320);
timeSeries1.add(new Month(8, 2007), 830);
timeSeries1.add(new Month(9, 2007), 1240);
timeSeries1.add(new Month(10, 2007), 1250);
timeSeries1.add(new Month(11, 2007), 1360);
timeSeries1.add(new Month(12, 2007), 1250);

TimeSeries timeSeries2 = new TimeSeries("阿蜜果blog访问量统计2", Month.class);

//构造数据集合
timeSeries2.add(new Month(1, 2007), 6000);
timeSeries2.add(new Month(2, 2007), 6000);
timeSeries2.add(new Month(3, 2007), 6000);
timeSeries2.add(new Month(4, 2007), 6000);
timeSeries2.add(new Month(5, 2007), 6000);
timeSeries2.add(new Month(6, 2007), 6000);
timeSeries2.add(new Month(7, 2007), 6000);
timeSeries2.add(new Month(8, 2007), 6000);
timeSeries2.add(new Month(9, 2007), 6000);
timeSeries2.add(new Month(10, 2007), 6000);
timeSeries2.add(new Month(11, 2007), 6000);
timeSeries2.add(new Month(12, 2007), 6000);

TimeSeries timeSeries3 = new TimeSeries("阿蜜果blog访问量统计3", Month.class);

//构造数据集合
timeSeries3.add(new Month(1, 2007), 8000);
timeSeries3.add(new Month(2, 2007), 8000);
timeSeries3.add(new Month(3, 2007), 8000);
timeSeries3.add(new Month(4, 2007), 8000);
timeSeries3.add(new Month(5, 2007), 8000);
timeSeries3.add(new Month(6, 2007), 8000);
timeSeries3.add(new Month(7, 2007), 8000);
timeSeries3.add(new Month(8, 2007), 8000);
timeSeries3.add(new Month(9, 2007), 8000);
timeSeries3.add(new Month(10, 2007), 8000);
timeSeries3.add(new Month(11, 2007), 8000);
timeSeries3.add(new Month(12, 2007), 8000);

lineDataset.addSeries(timeSeries);
lineDataset.addSeries(timeSeries1);
lineDataset.addSeries(timeSeries2);
lineDataset.addSeries(timeSeries3);

//倒数第二个true设置当鼠标放上去后是否显示数据.
JFreeChart chart = ChartFactory.createTimeSeriesChart("访问量统计时间线", "月份", "访问量", lineDataset, true, true, true);

//整个的画布对象(chart),画布就相当与一个大的容器,包含一些图形元素,比如为一张白纸
chart.setBackgroundPaint(Color.white);

XYPlot plot = chart.getXYPlot();

org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = plot.getRenderer();
if(xyitemrenderer instanceof XYLineAndShapeRenderer)
{
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
    xylineandshaperenderer.setBaseShapesVisible(true);
    xylineandshaperenderer.setBaseShapesFilled(true);
}


//设置网格背景色
plot.setBackgroundPaint(Color.white);
//网格竖线的颜色
plot.setDomainGridlinePaint(Color.black);
//网格横线的颜色
plot.setRangeGridlinePaint(Color.black);
//plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
//曲线颜色, 注意第一个参数的意义是:设置第四个曲线为红色,0是第一个。
//plot.getRenderer().setSeriesPaint(3,Color.red);
//plot.getRenderer().setSeriesPaint(2,Color.BLUE);

//设置X轴的时间显示的形式
DateAxis dateaxis = (DateAxis)plot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));
//数据轴的数据标签是否自动确定
dateaxis.setAutoTickUnitSelection(true);
//设置横轴刻度以X月X日方式显示
//SimpleDateFormat format = new SimpleDateFormat("M月");
//dateaxis.setDateFormatOverride(format);
//横轴刻度为1月
//dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1));

//设置子标题
TextTitle subtitle = new TextTitle("2007年度", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
//设置主标题
chart.setTitle(new TextTitle("阿蜜果blog访问量统计", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
System.out.println();
String filename = ServletUtilities.saveChartAsPNG(chart, 800, 600, null, session);
System.out.println();
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
System.out.println();


//---------------以下是说明 start----------------------
/*
//设置背景颜色

chart.setBackgroundPaint(Color.pink);

//得到所有数据点的集合

XYPlot xyplot = (XYPlot) chart.getPlot();

//设定图表数据显示部分背景色

xyplot.setBackgroundPaint(Color.white);

//设置网格竖线颜色

xyplot.setDomainGridlinePaint(Color.red);

//设置网格横线颜色

xyplot.setRangeGridlinePaint(Color.red);

//设定坐标轴与图表数据显示部分距离

//参数1:上距 参数2:左距 参数3:下距 参数4:右距

xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));

xyplot.setDomainCrosshairVisible(true);

xyplot.setRangeCrosshairVisible(true);

XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyplot.getRenderer();

//设置曲线是否显示数据点

renderer.setBaseShapesVisible(true);

//设置显示的数据点为实心或空心

renderer.setBaseShapesFilled(true);

//设置线条的粗细

renderer.setBaseStroke(new BasicStroke(2));

//设置字体

Font labelFont = new Font("宋体", Font.TRUETYPE_FONT, 12);

//得到纵轴(纵轴为数值型)

NumberAxis naxis = (NumberAxis) xyplot.getRangeAxis();

//设置纵轴最小最大值

naxis.setRange(new Range(0, 70));

//设置纵轴刻度

naxis.setTickUnit(new NumberTickUnit(10));

//得到横轴(横轴为日期型)

DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();

//数据轴的数据标签是否自动确定

dateaxis.setAutoTickUnitSelection(false);

//设置横轴刻度以X月X日方式显示

SimpleDateFormat format = new SimpleDateFormat("M月");

dateaxis.setDateFormatOverride(format);

//横轴刻度为1天

dateaxis.setTickUnit(new DateTickUnit(DateTickUnit.MONTH,1));

//设置字体

dateaxis.setLabelFont(labelFont);

//设置曲线显示各数据点的值

XYItemRenderer xyitem = xyplot.getRenderer();

xyitem.setBaseItemLabelsVisible(true);

xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_LEFT));

xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());

xyitem.setBaseItemLabelFont(new Font("Dialog", 2, 14));

xyplot.setRenderer(xyitem);

*/

//---------------以下是说明 end----------------------

%>
<img src="<%= graphURL %>"width=800 height=600 border=0 usemap="#<%= filename %>">

-

01-01
-
©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值