Because the project needs to start Java and JFreeChart class libraries... It really hurts. I read this class library topic of 51cto: Workshop.
It's quite good. It's quite clear. It's just a bit coincident with the official demo. It's all pieChart. Do you dare to change another chart?
Below I will list the three necessary modules for drawing, and the other parts will not be provided one by one. If you need them, please take a look:
- // Load dataset. Ignore the specific business logic
- Public static XYDataset createxydataset (ArrayList <LineInfo> xydatalist, ArrayListMultimap <Integer, Integer> tabBat ){
- DefaultXYDataset dataset = new DefaultXYDataset ();
- LineInfo tabTmp = xydatalist. get (0 );
- Int numTmp = tabTmp. getMeterNum ();
- Set <Integer> allKey = tabBat. keySet ();
- Iterator <Integer> it = allKey. iterator ();
- Int keyTmp = 0;
- While (it. hasNext ())
- {
- KeyTmp = it. next ();
- If (tabBat. containsEntry (keyTmp, numTmp ))
- Break;
- }
- List <Integer> allNum = tabBat. get (keyTmp );
- Int allNumSize = allNum. size ();
- // Data is the core of data
- Double [] [] data = new double [2] [allNumSize];
- It = allNum. iterator ();
- Iterator <LineInfo> it2 = xydatalist. iterator ();
- Int tmp = 0, count = 0;
- LineInfo lineTmp = new LineInfo ();
- While (it. hasNext ())
- {
- Tmp = it. next ();
- It2 = xydatalist. iterator ();
- While (it2.hasNext ())
- {
- LineTmp = it2.next ();
- If (tmp = lineTmp. getMeterNum ())
- Break;
- }
- Data [0] [count] = lineTmp. getIntercept ();
- Data [1] [count] = lineTmp. getSlope ();
- Count ++;
- }
- // I still don't know the first parameter in addSeries. From the generated chart, it's just the description text in the chart.
- Dataset. addSeries ("table", data );
- Return dataset;
- }
-
- // Generate a chart object
- Public static JFreeChart createChart (XYDataset xydataset, String title, String xAxis, String yAxis ){
- JFreeChart scatterChart = ChartFactory. createScatterPlot (title, xAxis, yAxis, xydataset, PlotOrientation. VERTICAL, true, false, false );
- Return scatterChart;
- }
-
- // According to the chart object, set the Image Parameters and draw a picture. This is very important. If you do not pay attention to it, the text of the comment will be garbled.
- Public static void drawScatterChart (JFreeChart scatterChart, String title, String noDataMsg ){
- // Set the font for title, legend, and plot as follows:
- TextTitle textTitle = scatterChart. getTitle ();
- TextTitle. setFont (new Font ("", Font. BOLD, 20 ));
- LegendTitle legend = scatterChart. getLegend ();
- If (legend! = Null)
- {
- Legend. setItemFont (new Font ("", Font. BOLD, 20 ));
- }
- XYPlot scatterPlot = scatterChart. getXYPlot ();
- ScatterPlot. setNoDataMessage (noDataMsg );
- // Draw the following three rows:
- ChartFrame scatterFrame = new ChartFrame (title, scatterChart );
- ScatterFrame. pack ();
- ScatterFrame. setVisible (true );
- }
In general, it is quite simple to draw other diagrams to check the API.
This article is from the title cannot be blank blog, please be sure to keep this source http://hector.blog.51cto.com/4229131/926904