<%@ page contentType="text/html; charset=GBK" %>
<%@ page import = " org.jfree.chart.*"%>
<%@ page import = " org.jfree.chart.renderer.category.BarRenderer"%>
<%@ page import = " org.jfree.chart.entity.*"%>
<%@ page import = " org.jfree.chart.servlet.*"%>
<%@ page import = "org.jfree.chart.*"%>
<%@ page import = "org.jfree.chart.axis.*"%>
<%@ page import = "org.jfree.chart.plot.*"%>
<%@ page import = "java.util.ArrayList"%>
<%@ page import = "org.jfree.chart.renderer.category.LineAndShapeRenderer"%>
<%@ page import = "java.awt.Color"%>
<%@ page import = "org.jfree.chart.ChartFactory"%>
<%@ page import = "org.jfree.chart.JFreeChart"%>
<%@ page import = "org.jfree.chart.plot.PlotOrientation"%>
<%@ page import ="org.jfree.chart.plot.CategoryPlot"%>
<%@ page import ="org.jfree.chart.axis.CategoryAxis"%>
<%@ page import ="org.jfree.chart.axis.ValueAxis"%>
<%@ page import ="org.jfree.chart.renderer.category.BarRenderer3D"%>
<%@ page import ="org.jfree.chart.renderer.category.BarRenderer"%>
<%@ page import ="org.jfree.chart.axis.AxisLocation"%>
<%@ page import ="org.jfree.data.category.DefaultCategoryDataset"%>
<html>
<head>
<title>
Line
</title>
</head>
<%
DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
String serias1 = "温度";
String serias2 = "电流";
dataset1.addValue(90,serias1,"1");
dataset1.addValue(80,serias1,"2");
dataset1.addValue(70,serias1,"3");
dataset1.addValue(60,serias1,"4");
dataset1.addValue(50,serias1,"5");
dataset1.addValue(40,serias1,"6");
dataset1.addValue(30,serias1,"7");
dataset1.addValue(20,serias1,"8");
dataset1.addValue(10,serias1,"9");
JFreeChart chart = ChartFactory.createLineChart(
" 日报分析图表", // chart title 标题
"Time", // domain axis label 种类轴文本(X轴的文本)
"MA", // range axis label 值轴文本(Y轴的文本)
dataset1, // data 联合的数据
PlotOrientation.VERTICAL, // orientation 用来在制作 2D 图形时指定方位(X轴,Y轴的位置)
true, // include legend 图例
true, // tooltips 工具提示
false // urls 地址
);
//CategoryPlot 对象的 x 轴是 CategoryAxis 对象, y 轴是 NumberAxis 对象,
//绘制单元是 BarRenderer 对象,数据源是 CategoryDataset 对象。
final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(new Color(0xEE, 0xEE, 0xFF));
plot.setRangeGridlinePaint(Color.BLUE); //纵坐标格线颜色
plot.setDomainGridlinePaint(Color.BLACK); //横坐标格线颜色
plot.setDomainGridlinesVisible(true); //显示横坐标格线
plot.setRangeGridlinesVisible(true); //显示纵坐标格线
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);
plot.setBackgroundAlpha(0.5f);
plot.setForegroundAlpha(0.8f);
ValueAxis valueAxis = (ValueAxis) plot.getRangeAxis();
valueAxis.setUpperBound(100); // 数据轴上的显示最大值
valueAxis.setLowerBound(10); // 数据轴上的显示最小值
plot.setRangeAxis(valueAxis);
//控制Y轴的位置
valueAxis.setUpperMargin(0.20);
//控制X轴的位置
valueAxis.setLabelAngle(Math.PI / 2.0);
DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
dataset2.addValue(1,serias2,"1");
dataset2.addValue(2,serias2,"2");
dataset2.addValue(3,serias2,"3");
dataset2.addValue(4,serias2,"4");
dataset2.addValue(5,serias2,"5");
dataset2.addValue(6,serias2,"6");
dataset2.addValue(7,serias2,"7");
dataset2.addValue(8,serias2,"8");
dataset2.addValue(9,serias2,"9");
plot.setDataset(1, dataset2);
plot.mapDatasetToRangeAxis(1, 1);
// Maps a dataset to a particular range axis.
// plot.mapDatasetToRangeAxis(1, 1);
CategoryAxis domainAxis = plot.getDomainAxis();
//设置 CategoryLabelPositions 文字的方位
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
/*
A renderer that draws shapes for each data item, and lines
between data items (for use with the CategoryPlot class).
*/
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
ValueAxis axis2 = new NumberAxis("℃");
axis2.setUpperBound(10); // 温度的显示最大 值
axis2.setLowerBound(1); //温度的显示最小值
// Sets a range axis and sends a PlotChangeEvent to all registered listeners
plot.setRangeAxis(1, axis2);
//绘制单元对象 LineAndShapeRenderer
final LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
plot.setRenderer(1, renderer2);
//设置图标是否可见
renderer2.setBaseShapesVisible(false);
renderer2.setBaseLinesVisible(true);
plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
String filename = ServletUtilities.saveChartAsPNG(chart, 720, 460, info,session);
String graphXYURL = request.getContextPath() +"/servlet/DisplayChart?filename=" + filename;
%>
<body bgcolor="#ffffff">
<h4 align="center">
双Y轴曲线
</h4>
<br/> <br/>
<img align="middle" src=" <%= graphXYURL %>" width=750 height=450 border=1 usemap="# <%= filename %>" alt="">
</body>
</html>