感谢大姐的这篇文章,顺便问下大姐.为什么我做2个曲线比较的时候,2条曲线是分开的啊,一个在左边,一个在右边.
代码如下
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.time.Month;
import org.jfree.data.time.Day;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.chart.title.TextTitle;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.labels.*;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
import java.awt.Font;
import java.awt.Color;
import java.io.*;
public class ChartUtil {
public static JFreeChart draw() throws IOException {
TimeSeries series = new TimeSeries("a small test", Month.class);
TimeSeries series2=new TimeSeries("the seconde test",Month.class);
TimeSeriesCollection collection = new TimeSeriesCollection();
series2.add(new Month(1, 2006), 100000);
series2.add(new Month(2, 2006), 10);
series2.add(new Month(3, 2006), 100);
series2.add(new Month(4, 2006), 1000);
series2.add(new Month(5, 2006), 1021);
series2.add(new Month(6, 2006), 10343);
series2.add(new Month(7, 2006), 1053);
series2.add(new Month(9, 2006), 103300);
series2.add(new Month(8, 2006), 100000);
series2.add(new Month(10, 2006), 1002);
series2.add(new Month(11, 2006), 1022);
series2.add(new Month(12, 2006), 123);
series.add(new Month(1, 2007), 100000);
series.add(new Month(2, 2007), 10);
series.add(new Month(3, 2007), 100);
series.add(new Month(4, 2007), 1000);
series.add(new Month(5, 2007), 1021);
series.add(new Month(6, 2007), 10343);
series.add(new Month(7, 2007), 1053);
series.add(new Month(9, 2007), 103300);
series.add(new Month(8, 2007), 100000);
series.add(new Month(10, 2007), 100);
series.add(new Month(11, 2007), 10);
series.add(new Month(12, 2007), 1);
collection.addSeries(series);
collection.addSeries(series2);
JFreeChart chart = ChartFactory.createTimeSeriesChart("一个曲线图的测试", "月份",
"访问量", collection, true, true, true);
TextTitle subtitle = new TextTitle("2007年度", new Font("黑体", Font.BOLD,
12));
chart.addSubtitle(subtitle);
chart.setTitle(new TextTitle("the titile", new Font("隶书", Font.PLAIN,
32)));
chart.setAntiAlias(true);
return chart;
}
回复 更多评论