The implementation of the line chart is divided into the following steps:
1, the first step: Data preparation
Xymultipleseriesdataset mdataset = new Xymultipleseriesdataset ();
Xyseries series1 = new Xyseries ("first line");
Series1.add (1, 7);
Series1.add (2, 9);
Series1.add (3,12);
Series1.add (4, 5);
Mdataset.addseries (SERIES1);
Xyseries Series2 = new Xyseries ("second line");
Series2.add (1, 3);
Series2.add (2, 8);
Series2.add (3, 7);
Series2.add (4, 4);
Mdataset.addseries (Series2);
The second step is the implementation of the Xymultipleseriesrenderer, which is the setting of the description device
The main implementation of this is the drawing of the axes including, font size, the setting of the scale of the axis
For example Xymultipleseriesrenderer mrenderer = new Xymultipleseriesrenderer (); Sets the current direction of the x-axis of the chart mrenderer.setorientation (XYMultipleSeriesRenderer.Orientation.HORIZONTAL);
Mrenderer.setxtitle ("date");//The title set to the x-axis
Mrenderer.setytitle ("Temperature");//Set the title of the y-axis
Mrenderer.setaxistitletextsize (20);//Set axis title text size
Mrenderer.setcharttitle ("Temperature Chart");//Set Chart title
Mrenderer.setcharttitletextsize (30);//Set the size of the chart title text
Mrenderer.setlabelstextsize (18);//Set the text size of the label
Mrenderer.setlegendtextsize (20);//Set legend text size
Mrenderer.setpointsize (10f);//Set point size
Mrenderer.setyaxismin (0);//Set y-axis minimum value is 0
Mrenderer.setyaxismax (15);
Mrenderer.setylabels (10);//Set the number of y-axis ticks (seemingly inaccurate)
Mrenderer.setxaxismax (5);
Mrenderer.setshowgrid (TRUE);//Display grid
Display x label columns such as: 1,2,3,4 Replace with display January, February, March, April
Mrenderer.addxtextlabel (1, "January");
Mrenderer.addxtextlabel (2, "February");
Mrenderer.addxtextlabel (3, "March");
Mrenderer.addxtextlabel (4, "April");
Mrenderer.setxlabels (0);//Set only display such as January, February and other after the replacement of things, do not display such as
Mrenderer.setmargins (New int[] {20, 30, 15, 20});//Set View location
Step three: setting of line chart lines
Xyseriesrenderer r = new Xyseriesrenderer ();//(similar to a line object)
R.setcolor (Color.Blue);//Set color
R.setpointstyle (pointstyle.circle);//The style of the set point
R.setfillpoints (TRUE);//Fill point (the displayed point is hollow or solid)
R.setdisplaychartvalues (TRUE);//Displays the value of the point
R.setchartvaluesspacing (10);//The distance between the value of the displayed point and the graph
R.setchartvaluestextsize (25);//The text size of the value of the point
R.setfillbelowline (TRUE);//whether to fill the bottom of the line chart
R.setfillbelowlinecolor (Color.green);//Fill color, if not set the default is the same as the color of the line
R.setlinewidth (3);//Set line width
Mrenderer.addseriesrenderer (R);
Xyseriesrenderer rtwo = new Xyseriesrenderer ();//(similar to a line object)
Rtwo.setcolor (Color.gray);//Set color
Rtwo.setpointstyle (pointstyle.circle);//The style of the set point
Rtwo.setfillpoints (TRUE);//Fill point (the displayed point is hollow or solid)
Rtwo.setdisplaychartvalues (TRUE);//Displays the value of the point
Rtwo.setchartvaluesspacing (10);//The distance between the value of the displayed point and the graph
Rtwo.setchartvaluestextsize (25);//The text size of the value of the point
Rtwo.setfillbelowline (TRUE);//whether to fill the bottom of the line chart
Rtwo.setfillbelowlinecolor (Color.green);//Fill color, if not set the default is the same as the color of the line
Rtwo.setlinewidth (3);//Set line width
Mrenderer.addseriesrenderer (Rtwo);
Fourth step: Generate Diagram view
Graphicalview view = Chartfactory.getlinechartview (this, mdataset, mrenderer);
View.setbackgroundcolor (Color.Black);
Android uses Achartengine to implement line charts