67,515
社区成员
发帖
与我相关
我的任务
分享
charti[i] = ChartFactory.createTimeSeriesChart("统计时间线", "月份",
"值", lineDatasets[i], true, true, true);
// 设置标题
charti[i].setTitle(new TextTitle("\"" + md + bkn[i]
+ "\"指标值示意图", new Font("雅黑", Font.BOLD, 25)));
// 设置图表部分
charti[i].setTextAntiAlias(true);
charti[i].setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) charti[i].getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) plot
.getRenderer();
// 设置曲线是否显示数据点
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(
ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));
xyitem
.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
plot.getDomainAxis()
.setLabelFont(new Font("宋体", Font.BOLD, 15));
plot.getDomainAxis().setTickLabelFont(
new Font("宋体", Font.BOLD, 10));
plot.getRangeAxis().setLabelFont(new Font("宋体", Font.BOLD, 15));
plot.getRangeAxis().setTickLabelFont(
new Font("宋体", Font.BOLD, 10));
plot.getRangeAxis().setLabelAngle(1.6);
charti[i].getLegend().setItemFont(
new Font("宋体", Font.PLAIN, 10)); // 设置最底下方框内的字体(图示)
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new java.text.SimpleDateFormat(
"yyyyMMdd"));
// 关键点
axis.setAutoTickUnitSelection(false);//
axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1));
charti[i].setAntiAlias(true);
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="org.jfree.chart.ChartFactory"%>
<%@ page import="org.jfree.chart.JFreeChart"%>
<%@ page import="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.data.category.DefaultCategoryDataset"%>
<%@ page import="org.jfree.data.general.DatasetUtilities"%>
<%@ page import="org.jfree.data.category.CategoryDataset"%>
<%@ page import="org.jfree.chart.renderer.category.BarRenderer3D"%>
<%@ page import="java.awt.Color"%>
<%@ page import="org.jfree.chart.plot.CategoryPlot"%>
<%@ page import="org.jfree.chart.axis.ValueAxis"%>
<%@ page import="org.jfree.chart.axis.AxisLocation"%>
<%@ page
import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator"%>
<%@ page import="org.jfree.chart.axis.*"%>
<%@ page import="org.jfree.chart.axis.CategoryAxis"%>
<%
double[][] data = new double[][] { { 672, 766, 223, 540, 126 }, { 325, 521, 210, 340, 106 },
{ 332, 256, 523, 240, 526 } };
String[] rowKeys = { "苹果", "梨子", "葡萄" };
String[] columnKeys = { "北京", "上海", "广州", "成都", "深圳" };
CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
JFreeChart chart = ChartFactory.createBarChart3D("水果销量图统计", null, null, dataset, PlotOrientation.VERTICAL,
true, false, false);
chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setVerticalCategoryLabels(false);
//domainAxis.setVerticalCategoryLabels(true);
plot.setDomainAxis(domainAxis);
ValueAxis rangeAxis = plot.getRangeAxis();
//设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(0.15);
plot.setRangeAxis(rangeAxis);
BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(0, 100, 255));
renderer.setSeriesPaint(2, Color.GREEN);
//设置每个地区所包含的平行柱的之间距离
renderer.setItemMargin(0.1);
//显示每个柱的数值,并修改该数值的字体属性
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setItemLabelsVisible(true);
plot.setRenderer(renderer);
//设置柱的透明度
plot.setForegroundAlpha(0.6f);
//设置地区、销量的显示位置
plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart filename=" + filename;
%>
<img src="<%=graphURL%>" width=500 height=300 border=0
usemap="#<%= filename %>">