當前位置:首頁 » 數據倉庫 » jfreechart與資料庫
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

jfreechart與資料庫

發布時間: 2023-08-13 04:14:32

Ⅰ Java如何調用資料庫中的數據畫圖

你需要下載導入JFREECHART的jar包
然後下面是一個例子
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

public class XYSeriesDemo extends ApplicationFrame {

/**
* A demonstration application showing an XY series containing a null value.
*
* @param title the frame title.
*/
public XYSeriesDemo(final String title) {

super(title);
final XYSeries series = new XYSeries("Random Data");
series.add(1.0, 500.2);
series.add(5.0, 694.1);
series.add(4.0, 100.0);
series.add(12.5, 734.4);
series.add(17.3, 453.2);
series.add(21.2, 500.2);
series.add(21.9, null);
series.add(25.6, 734.4);
series.add(30.0, 453.2);
final XYSeriesCollection data = new XYSeriesCollection(series);
final JFreeChart chart = ChartFactory.createXYLineChart(
"XY Series Demo",
"X",
"Y",
data,
PlotOrientation.VERTICAL,
true,
true,
false
);

final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);

}

public static void main(final String[] args) {

final XYSeriesDemo demo = new XYSeriesDemo("XY Series Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true);

}

}

series.add(1.0, 500.2);1.0,500.2分別是橫坐標和縱坐標數值 它會自動產生橫豎坐標的

Ⅱ 如何用jfreechart顯示餅狀圖,數據來自我的資料庫當中。求具體代碼

/*
*生成3D餅狀圖
*/
(Stringtitle,
List<TimeSeriesDataBean>list){
FontCtl.setFont();//解決亂碼問題
List<String[]>dataList=newArrayList<String[]>();
String[]ss;
for(TimeSeriesDataBeanbean:list){
ss=newString[2];
ss[0]=bean.getNam();
ss[1]=bean.getVal()+"";
dataList.add(ss);
}
DefaultPieDatasetdataset=DataSetBuilder.buildPieChartDataSet(title,
dataList);
JFreeChartchart=ChartFactory.createPieChart3D(title,dataset,true,
true,false);
//chart.addSubtitle(newTextTitle("SUBTITLE測試"));
PiePlotpieplot=(PiePlot)chart.getPlot();
//{0}:({1})%代表顯示格式:0=名稱1=值比如:名稱:19%
=(
"{0}:({1})",NumberFormat.getNumberInstance(),NumberFormat
.getPercentInstance());
pieplot.setLabelGenerator(standarPieIG);
//沒有數據的時候顯示的內容
pieplot.setNoDataMessage("無數據顯示");
pieplot.setLabelGap(0.02D);
PiePlot3Dpieplot3d=(PiePlot3D)chart.getPlot();
//設置開始角度
pieplot3d.setStartAngle(120D);
//設置方向為」順時針方向「
pieplot3d.setDirection(Rotation.CLOCKWISE);
//設置透明度,0.5F為半透明,1為不透明,0為全透明
pieplot3d.setForegroundAlpha(0.7F);
ChartFrameframe=newChartFrame(title,chart);
frame.pack();
frame.setVisible(true);
returnchart;
}