用了二天的時間做到這個效果
加上和JFreeChart 官方人員聯繫的協助
終於有了以下的結果
真是太高興了
不得不一反常態的把這code放上來
太爽了~~~~~~~~~![](http://spaces.msn.com/rte/emoticons/smile_teeth.gif)
![](http://spaces.msn.com/rte/emoticons/smile_teeth.gif)
=====================================================
/*
* Created on 2005/8/2
* @author tony
*/
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
* Created on 2005/8/2
* @author tony
*/
import org.jfree.chart.*;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.data.xy.XYSeriesCollection;
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author tony
* make sure the XYLine in two color (or more)
*/
public class TestXYPlot {
* @author tony
* make sure the XYLine in two color (or more)
*/
public class TestXYPlot {
private XYSeries series = null;
private XYSeriesCollection xyDataset = new XYSeriesCollection();
private XYSeriesCollection xyDataset = new XYSeriesCollection();
public void createSeries(double doubleX, double doubleY,String seriesName) throws IOException{
series = new XYSeries(seriesName,true,false);
this.addData(series,doubleX,doubleY);
series.add(200,100);//add this twice
xyDataset.addSeries(series);
}
private void addData(XYSeries series,double doubleX, double doubleY){
if(this.series != null){
series.add(doubleX,doubleY);
}
}
series = new XYSeries(seriesName,true,false);
this.addData(series,doubleX,doubleY);
series.add(200,100);//add this twice
xyDataset.addSeries(series);
}
private void addData(XYSeries series,double doubleX, double doubleY){
if(this.series != null){
series.add(doubleX,doubleY);
}
}
public TestXYPlot() throws Exception{
super();
super();
this.createSeries(100,300,"qualified合格");
this.createSeries(300,500,"unqualified不合格");
this.createSeries(300,500,"unqualified不合格");
JFreeChart jfreechart = ChartFactory.createXYLineChart("TestXYPlot.jpg",
"", "", xyDataset, PlotOrientation.VERTICAL, true, true, false);
"", "", xyDataset, PlotOrientation.VERTICAL, true, true, false);
XYPlot xyplot = (XYPlot) jfreechart.getPlot();
xyplot.setRangeGridlinePaint(Color.ORANGE);//格線顏色(Grid Line color)
/***
* 將符合八大規則的線段指定為藍色,而線段預設顏色為紅色
* series(XYLine) first default color is red
* If you have more series,JFreeChart will control color by itself,but you can reset it.
**/
//setSeriesPaint(int args,ChartColor.BLUE);the args : It is ths series(XYLine) No.
jfreechart.getXYPlot().getRenderer().setSeriesPaint(0,ChartColor.BLUE);//set XYLine color
// jfreechart.getXYPlot().getRenderer().setStroke(new BasicStroke(10));//XYLine寬度(XYLine wide)
// jfreechart.getXYPlot().getRenderer().setBaseSeriesVisibleInLegend(false);//說明出現與否(Legend appear or not)
xyplot.setRangeGridlinePaint(Color.ORANGE);//格線顏色(Grid Line color)
/***
* 將符合八大規則的線段指定為藍色,而線段預設顏色為紅色
* series(XYLine) first default color is red
* If you have more series,JFreeChart will control color by itself,but you can reset it.
**/
//setSeriesPaint(int args,ChartColor.BLUE);the args : It is ths series(XYLine) No.
jfreechart.getXYPlot().getRenderer().setSeriesPaint(0,ChartColor.BLUE);//set XYLine color
// jfreechart.getXYPlot().getRenderer().setStroke(new BasicStroke(10));//XYLine寬度(XYLine wide)
// jfreechart.getXYPlot().getRenderer().setBaseSeriesVisibleInLegend(false);//說明出現與否(Legend appear or not)
XYLineAndShapeRenderer xylineshaperender = (XYLineAndShapeRenderer)xyplot.getRenderer();
xylineshaperender.setShapesVisible(false);//控制座標點出現與否(set the shape point appear or not)
xylineshaperender.setShapesVisible(false);//控制座標點出現與否(set the shape point appear or not)
FileOutputStream jpgoutput = new FileOutputStream("c://xy.jpg");
ChartUtilities.writeChartAsJPEG(jpgoutput, 100,
jfreechart, 700, 500, null);
jfreechart, 700, 500, null);
jpgoutput.close();
}
}
public static void main(String args[])throws Exception{
new TestXYPlot();
System.out.println("it is finished");
}
new TestXYPlot();
System.out.println("it is finished");
}
}
======================================================
======================================================
原理:
要同一條線設置二種以上顏色在JFreeChart中是不可能的
但用點小技巧就可以在畫面上看到這種效果
把一條線「拆」成好多條
指定某些線段是另一個顏色
就可以達到所要求的效果了^^
小技巧:
二個點做成一條線
所以,重覆使用的點要add二次
=======================================================
0805
今天發現還有一種更正統的做法咧
目前還沒研究出來
研究出來一定貼出來的
(看到上面的code,金害,不知道有沒有誤導人了咧)
全站熱搜