第一種方法:
// 日期軸日期標籤的顯示格式
xAxis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
// 設定時間軸單位(設定最小單位為天)
DateTickUnit dtu = new DateTickUnit(DateTickUnit.DAY, // 最小單位
1);
xAxis.setTickUnit(dtu);
// 資料軸資料標籤旋轉到垂直(ture將日期垂直顯示,false將日期橫向顯示)
xAxis.setVerticalTickLabels(true);
// 建立時間順序圖的XYPlot的執行個體
XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true,
false);
// 設定第四條下載折線為黑色(下標從0開始)曲線數量超過五條時顏色自動化佈建少於五個安順序配置顏色
renderer.setSeriesPaint(0, Color.cyan);
renderer.setSeriesPaint(1, Color.magenta);
renderer.setSeriesPaint(2, Color.blue);
renderer.setSeriesPaint(3, Color.red);
renderer.setSeriesPaint(4, Color.green);
// 資料區的表示者(不設定看不到折線)
plot.setRenderer(renderer);
// 設定chart的樣式
chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
chart.setBackgroundPaint(java.awt.Color.WHITE); // 設定圖片的背景色
chart.setBackgroundImageAlpha(0.5f);// 背景圖片透明度(0.0~1.0)
Font font = new Font("黑體", Font.CENTER_BASELINE, 20);// 設定圖片標題的字型和大小
TextTitle _title = new TextTitle(title);
_title.setFont(font);
chart.setTitle(_title);
第二種方法:
修改了jfreechart的原始碼。在項目中做曲線圖的時候,各條曲線圖的顏色不能顯示的設定。在網上查資料也沒有找到哦,只好修改原始碼了。後來看到在org.jfree.chart.ChartColor類中,修改方法public static Paint[] createDefaultPaintArray()就可以了哦,這幾個paint顏色就是各條出來的曲線圖的顏色,進行相應的修改就可以按順序得到自己想到的曲線顏色了。