58,454
社区成员
发帖
与我相关
我的任务
分享
public class LineMode {
String title;
String xname;
String y1name;
String y2name;
String l1name;
String l2name;
int x,y;
XYSeriesCollection ld1,ld2;
public LineMode(String title,String xname,String y1name,String y2name,int x,int y){
this.title=title;
this.xname=xname;
this.y1name=y1name;
this.y2name=y2name;
this.x=x;
this.y=y;
}
public void setLname(String l1,String l2){
this.l1name=l1;
this.l2name=l2;
}
public void createDataset1(int number,double[] data,int[] date){
XYSeries xyseries = new XYSeries(l1name);
for(int i=0;i<number;i++){
xyseries.add(date[i], data[i]);
}
ld1 = new XYSeriesCollection();
ld1.addSeries(xyseries);
}
public void createDataset2(int number,double[] data,int[] date){
XYSeries xyseries = new XYSeries(l2name);
for(int i=0;i<number;i++){
xyseries.add(date[i], data[i]);
}
ld2 = new XYSeriesCollection();
ld2.addSeries(xyseries);
}
public JFreeChart draw(){
XYDataset xydataset = ld1;
JFreeChart jfreechart = ChartFactory.createXYLineChart(title, xname, y1name, xydataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
NumberAxis numberaxis = (NumberAxis)xyplot.getRangeAxis();
numberaxis.setAutoRangeIncludesZero(false);
NumberAxis numberaxis1 = new NumberAxis(y2name);
numberaxis1.setAutoRangeIncludesZero(false);
xyplot.setRangeAxis(1, numberaxis1);
xyplot.setDataset(1, ld2);
xyplot.mapDatasetToRangeAxis(1, 1);
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyplot.getRenderer();
XYLineAndShapeRenderer xylineandshaperenderer1 = new XYLineAndShapeRenderer(true, true);
xylineandshaperenderer1.setSeriesPaint(0, Color.black);
xyplot.setRenderer(1, xylineandshaperenderer1);
LegendTitle legendtitle = new LegendTitle(xylineandshaperenderer);
LegendTitle legendtitle1 = new LegendTitle(xylineandshaperenderer1);
BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
blockcontainer.add(legendtitle, RectangleEdge.LEFT);
blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
blockcontainer.add(new EmptyBlock(2000D, 0.0D));
CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
compositetitle.setPosition(RectangleEdge.BOTTOM);
jfreechart.addSubtitle(compositetitle);
jfreechart.getTitle().setFont(new Font("宋体", Font.BOLD, 15));
jfreechart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 15));
ValueAxis domainAxis = xyplot.getDomainAxis();
domainAxis.setTickLabelFont(new Font("黑体", Font.PLAIN, 11));
domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12));
NumberAxis numberaxis11 = (NumberAxis) xyplot.getRangeAxis();
numberaxis11.setTickLabelFont(new Font("黑体", Font.PLAIN, 12));
numberaxis11.setLabelFont(new Font("黑体", Font.PLAIN, 12));
return jfreechart;
}
}