在JfreeChart中如何设置Y轴的起点坐标?[jsp] ( 积分: 100 )

  • 主题发起人 主题发起人 abencat
  • 开始时间 开始时间
A

abencat

Unregistered / Unconfirmed
GUEST, unregistred user!
在JfreeChart中如何设置Y轴的起点坐标?,而不是系统自动给的.
程序如下:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import = "java.awt.Color "%>
<%@ page import="java.awt.Color "%>
<%@ page import="org.jfree.chart.ChartFactory "%>
<%@ page import="org.jfree.chart.ChartPanel "%>
<%@ page import="
org.jfree.chart.JFreeChart "%>
<%@ page import="
org.jfree.chart.Spacer "%>
<%@ page import="
org.jfree.chart.axis.AxisLocation "%>
<%@ page import="
org.jfree.chart.axis.NumberAxis "%>
<%@ page import="
org.jfree.chart.plot.PlotOrientation "%>
<%@ page import="
org.jfree.chart.plot.XYPlot "%>
<%@ page import="
org.jfree.chart.renderer.StandardXYItemRenderer "%>
<%@ page import="
org.jfree.chart.title.TextTitle "%>
<%@ page import="
org.jfree.data.XYDataset "%>
<%@ page import="
org.jfree.data.time.Minute "%>
<%@ page import="
org.jfree.data.time.Day "%>
<%@ page import="
org.jfree.data.time.RegularTimePeriod "%>
<%@ page import="
org.jfree.data.time.TimeSeries "%>
<%@ page import="
org.jfree.data.time.TimeSeriesCollection "%>
<%@ page import="
org.jfree.ui.ApplicationFrame "%>
<%@ page import="
org.jfree.ui.RefineryUtilities "%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import = "testchart.*"%>
<%@ page import= "
java.text.SimpleDateFormat "%>
<%@ page import = "org.jfree.chart.ChartFactory "%>
<%@ page import = "org.jfree.chart.ChartPanel"
%>
<%@ page import = "org.jfree.chart.JFreeChart "%>
<%@ page import= "
org.jfree.chart.Spacer"
%>
<%@ page import = "org.jfree.chart.StandardLegend "%>
<%@ page import = "org.jfree.chart.axis.DateAxis "%>
<%@ page import = "org.jfree.chart.plot.XYPlot "%>
<%@ page import = "org.jfree.chart.renderer.StandardXYItemRenderer "%>
<%@ page import = "org.jfree.chart.renderer.XYItemRenderer "%>
<%@ page import = "org.jfree.data.XYDataset "%>
<%@ page import = "org.jfree.data.time.Month "%>
<%@ page import = "org.jfree.data.time.TimeSeries "%>
<%@ page import ="org.jfree.data.time.TimeSeriesCollection "%>
<%@ page import= "
org.jfree.ui.ApplicationFrame"
%>
<%@ page import = "org.jfree.ui.RefineryUtilities"
%>
<%@ page import = "org.jfree.chart.axis.ValueAxis"
%>
<%@ page import = "testchart.*"%>
<%

//带点的曲线图形
XYDataset dataset;

TimeSeries s1 = new TimeSeries("水位",Day.class);
s1.add(new Day(1, 2, 2005), 1954.3);
s1.add(new Day(2, 2, 2005), 1820.3);
s1.add(new Day(3, 2, 2005), 1843.4);
s1.add(new Day(28, 2, 2005),1988);
TimeSeries s2 = new TimeSeries("基准高程",Day.class);
s2.add(new Day(1, 2, 2005), 100);
s2.add(new Day(28, 2, 2005), 100);

TimeSeriesCollection dataset1 = new TimeSeriesCollection();
dataset1.addSeries(s1);
// dataset1.addSeries(s2);
dataset1.setDomainIsPointsInTime(true);
dataset=dataset1;

JFreeChart chart = ChartFactory.createTimeSeriesChart(
"在JfreeChart中如何设置Y轴的起点坐标?",
"日期", "水位",
dataset,
true,
true,
false
);
chart.setBackgroundPaint(Color.white);
//设置显示不同线的点样式
StandardLegend sl = (StandardLegend) chart.getLegend();
sl.setDisplaySeriesShapes(true);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 1.0, 1.0, 1.0, 1.0));
//显示点
XYItemRenderer renderer = plot.getRenderer();
if (renderer instanceof StandardXYItemRenderer) {
StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
rr.setPlotShapes(true);
rr.setShapesFilled(true);
}

//设置显示X日期格式
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("d"));
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setAutoRangeMinimumSize(1750);

//显示图象
String filename = ServletUtilities.saveChartAsPNG(chart,500, 300, null, session);
String graphURL = request.getContextPath()+ "/servlet/DisplayChart?filename="
+ filename;
// String graphURL1 =request.getContextPath()+ "/servlet/JFCtSvt?filename="
+ filename;
//String sURL="/JspChart/servlet/JFCtSvt";
%>
<HTML>
<HEAD>
<TITLE>www.sentom.net</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= graphURL %>"
width=500 height=300 border=0 usemap="#<%= filename %>">
</P>
</BODY>
</HTML>
 
在JfreeChart中如何设置Y轴的起点坐标?,而不是系统自动给的.
程序如下:
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import = "java.awt.Color "%>
<%@ page import="java.awt.Color "%>
<%@ page import="org.jfree.chart.ChartFactory "%>
<%@ page import="org.jfree.chart.ChartPanel "%>
<%@ page import="
org.jfree.chart.JFreeChart "%>
<%@ page import="
org.jfree.chart.Spacer "%>
<%@ page import="
org.jfree.chart.axis.AxisLocation "%>
<%@ page import="
org.jfree.chart.axis.NumberAxis "%>
<%@ page import="
org.jfree.chart.plot.PlotOrientation "%>
<%@ page import="
org.jfree.chart.plot.XYPlot "%>
<%@ page import="
org.jfree.chart.renderer.StandardXYItemRenderer "%>
<%@ page import="
org.jfree.chart.title.TextTitle "%>
<%@ page import="
org.jfree.data.XYDataset "%>
<%@ page import="
org.jfree.data.time.Minute "%>
<%@ page import="
org.jfree.data.time.Day "%>
<%@ page import="
org.jfree.data.time.RegularTimePeriod "%>
<%@ page import="
org.jfree.data.time.TimeSeries "%>
<%@ page import="
org.jfree.data.time.TimeSeriesCollection "%>
<%@ page import="
org.jfree.ui.ApplicationFrame "%>
<%@ page import="
org.jfree.ui.RefineryUtilities "%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import = "testchart.*"%>
<%@ page import= "
java.text.SimpleDateFormat "%>
<%@ page import = "org.jfree.chart.ChartFactory "%>
<%@ page import = "org.jfree.chart.ChartPanel"
%>
<%@ page import = "org.jfree.chart.JFreeChart "%>
<%@ page import= "
org.jfree.chart.Spacer"
%>
<%@ page import = "org.jfree.chart.StandardLegend "%>
<%@ page import = "org.jfree.chart.axis.DateAxis "%>
<%@ page import = "org.jfree.chart.plot.XYPlot "%>
<%@ page import = "org.jfree.chart.renderer.StandardXYItemRenderer "%>
<%@ page import = "org.jfree.chart.renderer.XYItemRenderer "%>
<%@ page import = "org.jfree.data.XYDataset "%>
<%@ page import = "org.jfree.data.time.Month "%>
<%@ page import = "org.jfree.data.time.TimeSeries "%>
<%@ page import ="org.jfree.data.time.TimeSeriesCollection "%>
<%@ page import= "
org.jfree.ui.ApplicationFrame"
%>
<%@ page import = "org.jfree.ui.RefineryUtilities"
%>
<%@ page import = "org.jfree.chart.axis.ValueAxis"
%>
<%@ page import = "testchart.*"%>
<%

//带点的曲线图形
XYDataset dataset;

TimeSeries s1 = new TimeSeries("水位",Day.class);
s1.add(new Day(1, 2, 2005), 1954.3);
s1.add(new Day(2, 2, 2005), 1820.3);
s1.add(new Day(3, 2, 2005), 1843.4);
s1.add(new Day(28, 2, 2005),1988);
TimeSeries s2 = new TimeSeries("基准高程",Day.class);
s2.add(new Day(1, 2, 2005), 100);
s2.add(new Day(28, 2, 2005), 100);

TimeSeriesCollection dataset1 = new TimeSeriesCollection();
dataset1.addSeries(s1);
// dataset1.addSeries(s2);
dataset1.setDomainIsPointsInTime(true);
dataset=dataset1;

JFreeChart chart = ChartFactory.createTimeSeriesChart(
"在JfreeChart中如何设置Y轴的起点坐标?",
"日期", "水位",
dataset,
true,
true,
false
);
chart.setBackgroundPaint(Color.white);
//设置显示不同线的点样式
StandardLegend sl = (StandardLegend) chart.getLegend();
sl.setDisplaySeriesShapes(true);
XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 1.0, 1.0, 1.0, 1.0));
//显示点
XYItemRenderer renderer = plot.getRenderer();
if (renderer instanceof StandardXYItemRenderer) {
StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer;
rr.setPlotShapes(true);
rr.setShapesFilled(true);
}

//设置显示X日期格式
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("d"));
ValueAxis rangeAxis = plot.getRangeAxis();
rangeAxis.setAutoRangeMinimumSize(1750);

//显示图象
String filename = ServletUtilities.saveChartAsPNG(chart,500, 300, null, session);
String graphURL = request.getContextPath()+ "/servlet/DisplayChart?filename="
+ filename;
// String graphURL1 =request.getContextPath()+ "/servlet/JFCtSvt?filename="
+ filename;
//String sURL="/JspChart/servlet/JFCtSvt";
%>
<HTML>
<HEAD>
<TITLE>www.sentom.net</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= graphURL %>"
width=500 height=300 border=0 usemap="#<%= filename %>">
</P>
</BODY>
</HTML>
 
沙发接分,学习
 
多人接受答案了。
 
后退
顶部