1,多个副标题,颜色,间距。
2,一图多行。
一图多行有两种方法,一种是TimeSeriesCollection.addSeries(TimeSeries);可以add多个,(仿佛是)这样的话每一行不能单独设置某些属性。
另一种方法是XYPlot plot = (XYPlot) chart.getPlot();
然后plot.setDataset(2,TimeSeriesCollection);XYPlot set多个TimeSeriesCollection。这样,每条线的级别都和主线一样,可以设置很多的属性。
3,每一点带有值。
4,一图多行,显示值的控制。
5,多个坐标轴纵轴。
2,一图多行。
一图多行有两种方法,一种是TimeSeriesCollection.addSeries(TimeSeries);可以add多个,(仿佛是)这样的话每一行不能单独设置某些属性。
另一种方法是XYPlot plot = (XYPlot) chart.getPlot();
然后plot.setDataset(2,TimeSeriesCollection);XYPlot set多个TimeSeriesCollection。这样,每条线的级别都和主线一样,可以设置很多的属性。
3,每一点带有值。
4,一图多行,显示值的控制。
5,多个坐标轴纵轴。
1,一些小的属性设置。多个副标题,颜色,间距等(图一)
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
plot.setBackgroundAlpha(1);//设置透明度
plot.setBackgroundPaint(Color.BLUE);
plot.setDomainCrosshairPaint(Color.GREEN);
plot.setDomainGridlinePaint(Color.RED);
plot.setDomainTickBandPaint(Color.YELLOW);
plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
2,显示每一点的值(图二)。
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
plot.setBackgroundAlpha(1);//设置透明度
plot.setBackgroundPaint(Color.BLUE);
plot.setDomainCrosshairPaint(Color.GREEN);
plot.setDomainGridlinePaint(Color.RED);
plot.setDomainTickBandPaint(Color.YELLOW);
plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
3,两行数据-第一种模式,TimeSeriesCollection加载多个TimeSeries(图三)
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
TimeSeries timeSeries1 = new TimeSeries("第二条线", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
timeSeries1.add(new Month(1, 2009), 200);
timeSeries1.add(new Month(2, 2009), 201);
timeSeries1.add(new Month(3, 2009), 202);
timeSeries1.add(new Month(4, 2009), 203);
timeSeries1.add(new Month(5, 2009), 206);
timeSeries1.add(new Month(6, 2009), 1200);
timeSeries1.add(new Month(7, 2009), 205);
timeSeries1.add(new Month(8, 2009), 200);
timeSeries1.add(new Month(9, 2009), 405);
timeSeries1.add(new Month(10, 2009), 500);
timeSeries1.add(new Month(11, 2009), 201);
timeSeries1.add(new Month(12, 2009), 200);
lineDataset.addSeries(timeSeries1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
// plot.setBackgroundAlpha(1);//设置透明度
// plot.setBackgroundPaint(Color.BLUE);
// plot.setDomainCrosshairPaint(Color.GREEN);
// plot.setDomainGridlinePaint(Color.RED);
// plot.setDomainTickBandPaint(Color.YELLOW);
// plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
4,两行数据,第二种模式,通过XYPlot加载多个TimeSeriesCollection。(图四)
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
TimeSeries timeSeries1 = new TimeSeries("第二条线", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
timeSeries1.add(new Month(1, 2009), 200);
timeSeries1.add(new Month(2, 2009), 201);
timeSeries1.add(new Month(3, 2009), 202);
timeSeries1.add(new Month(4, 2009), 203);
timeSeries1.add(new Month(5, 2009), 206);
timeSeries1.add(new Month(6, 2009), 1200);
timeSeries1.add(new Month(7, 2009), 205);
timeSeries1.add(new Month(8, 2009), 200);
timeSeries1.add(new Month(9, 2009), 405);
timeSeries1.add(new Month(10, 2009), 500);
timeSeries1.add(new Month(11, 2009), 201);
timeSeries1.add(new Month(12, 2009), 200);
TimeSeriesCollection lineDataset1 = new TimeSeriesCollection();
lineDataset1.addSeries(timeSeries1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDataset(1,lineDataset1);//createTimeSeriesChart时候默认是第0个,这里是第一个。
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
// plot.setBackgroundAlpha(1);//设置透明度
// plot.setBackgroundPaint(Color.BLUE);
// plot.setDomainCrosshairPaint(Color.GREEN);
// plot.setDomainGridlinePaint(Color.RED);
// plot.setDomainTickBandPaint(Color.YELLOW);
// plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
plot.setBackgroundAlpha(1);//设置透明度
plot.setBackgroundPaint(Color.BLUE);
plot.setDomainCrosshairPaint(Color.GREEN);
plot.setDomainGridlinePaint(Color.RED);
plot.setDomainTickBandPaint(Color.YELLOW);
plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
2,显示每一点的值(图二)。
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
plot.setBackgroundAlpha(1);//设置透明度
plot.setBackgroundPaint(Color.BLUE);
plot.setDomainCrosshairPaint(Color.GREEN);
plot.setDomainGridlinePaint(Color.RED);
plot.setDomainTickBandPaint(Color.YELLOW);
plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
3,两行数据-第一种模式,TimeSeriesCollection加载多个TimeSeries(图三)
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
TimeSeries timeSeries1 = new TimeSeries("第二条线", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
timeSeries1.add(new Month(1, 2009), 200);
timeSeries1.add(new Month(2, 2009), 201);
timeSeries1.add(new Month(3, 2009), 202);
timeSeries1.add(new Month(4, 2009), 203);
timeSeries1.add(new Month(5, 2009), 206);
timeSeries1.add(new Month(6, 2009), 1200);
timeSeries1.add(new Month(7, 2009), 205);
timeSeries1.add(new Month(8, 2009), 200);
timeSeries1.add(new Month(9, 2009), 405);
timeSeries1.add(new Month(10, 2009), 500);
timeSeries1.add(new Month(11, 2009), 201);
timeSeries1.add(new Month(12, 2009), 200);
lineDataset.addSeries(timeSeries1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
// plot.setBackgroundAlpha(1);//设置透明度
// plot.setBackgroundPaint(Color.BLUE);
// plot.setDomainCrosshairPaint(Color.GREEN);
// plot.setDomainGridlinePaint(Color.RED);
// plot.setDomainTickBandPaint(Color.YELLOW);
// plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}
4,两行数据,第二种模式,通过XYPlot加载多个TimeSeriesCollection。(图四)
package ookj.ui.chart;
import java.awt.Color;
import java.awt.Font;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisSpace;
import org.jfree.chart.labels.ItemLabelAnchor;
import org.jfree.chart.labels.ItemLabelPosition;
import org.jfree.chart.labels.StandardXYItemLabelGenerator;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.TextAnchor;
/**
* @author pinkfloyd
*
*/
public class MqneyOpol {
public static void main(String[] args){
//首先构造数据
TimeSeries timeSeries = new TimeSeries("最简单的线形图2,包含标题、副标题、横纵轴的名称", Month.class);
TimeSeries timeSeries1 = new TimeSeries("第二条线", Month.class);
// 时间曲线数据集合
TimeSeriesCollection lineDataset = new TimeSeriesCollection();
// 构造数据集合
timeSeries.add(new Month(1, 2009), 100);
timeSeries.add(new Month(2, 2009), 101);
timeSeries.add(new Month(3, 2009), 102);
timeSeries.add(new Month(4, 2009), 103);
timeSeries.add(new Month(5, 2009), 106);
timeSeries.add(new Month(6, 2009), 600);
timeSeries.add(new Month(7, 2009), 105);
timeSeries.add(new Month(8, 2009), 200);
timeSeries.add(new Month(9, 2009), 205);
timeSeries.add(new Month(10, 2009), 900);
timeSeries.add(new Month(11, 2009), 101);
timeSeries.add(new Month(12, 2009), 100);
lineDataset.addSeries(timeSeries);
timeSeries1.add(new Month(1, 2009), 200);
timeSeries1.add(new Month(2, 2009), 201);
timeSeries1.add(new Month(3, 2009), 202);
timeSeries1.add(new Month(4, 2009), 203);
timeSeries1.add(new Month(5, 2009), 206);
timeSeries1.add(new Month(6, 2009), 1200);
timeSeries1.add(new Month(7, 2009), 205);
timeSeries1.add(new Month(8, 2009), 200);
timeSeries1.add(new Month(9, 2009), 405);
timeSeries1.add(new Month(10, 2009), 500);
timeSeries1.add(new Month(11, 2009), 201);
timeSeries1.add(new Month(12, 2009), 200);
TimeSeriesCollection lineDataset1 = new TimeSeriesCollection();
lineDataset1.addSeries(timeSeries1);
JFreeChart chart = ChartFactory.createTimeSeriesChart("某非人体重", "月份", "公斤", lineDataset, true, true, true);
//增加标题
// 设置子标题
TextTitle subtitle = new TextTitle("2009年", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
// 设置主标题,这里跟createTimeSeriesChart第一个参数作用相同,可以设置不同字体。
chart.setTitle(new TextTitle("某非人体重", new Font("隶书", Font.ITALIC, 15)));
chart.setAntiAlias(true);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDataset(1,lineDataset1);//createTimeSeriesChart时候默认是第0个,这里是第一个。
plot.setAxisOffset(new RectangleInsets(10,10,10,10));//图片区与坐标轴的距离
// plot.setBackgroundAlpha(1);//设置透明度
// plot.setBackgroundPaint(Color.BLUE);
// plot.setDomainCrosshairPaint(Color.GREEN);
// plot.setDomainGridlinePaint(Color.RED);
// plot.setDomainTickBandPaint(Color.YELLOW);
// plot.setDomainZeroBaselinePaint(Color.ORANGE);
plot.setOutlinePaint(Color.PINK);
plot.setInsets(new RectangleInsets(15,15,15,15));//坐标轴与最外延的距离
// plot.setOrientation(PlotOrientation.HORIZONTAL);//图形的方向,包括坐标轴。
AxisSpace as = new AxisSpace();
as.setLeft(25);
as.setRight(25);
plot.setFixedRangeAxisSpace(as);
chart.setPadding(new RectangleInsets(5,5,5,5));
chart.setNotify(true);
chart.addSubtitle(new TextTitle("右一个副标题"));//可以添加多个副标题
// 设置曲线是否显示数据点
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)plot.getRenderer();
xylineandshaperenderer.setBaseShapesVisible(true);
// 设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.INSIDE10, TextAnchor.BASELINE_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 14));
plot.setRenderer(xyitem);
//显示
ChartFrame frame = new ChartFrame("mQney.com线形图试验2", chart);
frame.pack();
frame.setVisible(true);
}
}