The experience of using hellocharts bag

Source: Internet
Author: User

First, the jar package is imported into Libs and then add enters the activity to invoke

Adding a layout to the XML

< Lecho.lib.hellocharts.view.LineChartView             Android:id = "@+id/line_chart"             android:layout_width= "Fill_parent"            android:layout_height= "300DP"  />

One is the horizontal axis, one is the data points group

Private Linechartview Linechart;     = {"10-22", "11-22", "12-22", "1-22", "6-22", "5-23", "5-22", "6-22", "5-23", "5-22"}; // x-axis callouts    int [] score= {50,42,90,33,10,74,22,18,79,20}; // data points    of the chart Private New Arraylist<pointvalue>();     Private New Arraylist<axisvalue> ();

3 Methods in OnCreate:

protected void onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);         = (Linechartview) Findviewbyid (R.id.line_chart);        Getaxisxlables (); // Get Dimensions        for x-axis Getaxispoints (); // get coordinate points        Initlinechart (); // Initialize    }

The specific implementation of the method:

/*** Set X-axis display*/    Private voidGetaxisxlables () { for(inti = 0; i < date.length; i++) {Maxisxvalues.add (NewAxisvalue (i). SetLabel (Date[i]); }           }    /*** Display of each point of the chart*/    Private voidgetaxispoints () { for(inti = 0; i < weather.length; i++) {Mpointvalues.add (NewPointvalue (i, weather[i])); }

Private voidInitlinechart () { line line=NewLine (mpointvalues) setcolor (Color.parsecolor ("#FFCD41"));//the color of the polyline (orange)List<line> lines =NewArraylist<line>(); Line.setshape (valueshape.circle);//the shape of each data point on a line chart here is a circle (there are three kinds: valueshape.square valueshape.circle valueshape.diamond)Line.setcubic (false);//whether the curve is smooth, that is, a curve or a polylineLine.setfilled (false);//whether to fill the area of the curveLine.sethaslabels (true);//whether the data coordinates of the curve are added with notes//line.sethaslabelsonlyforselected (true);//Click Data coordinates to prompt the data (set this line.sethaslabels (true); invalid)Line.sethaslines (true);//whether to use line display. If False, there are no curves, only dots are displayed.Line.sethaspoints (true);//whether to show dots if False then no origin is only a bit (each data point is a large dot)Lines.add (line); Linechartdata Data=NewLinechartdata ();          Data.setlines (lines); //axesAxis AxisX =NewAxis ();//X-AxisAxisx.sethastiltedlabels (true);//x axis whether the font is diagonal or straight, true is oblique displayAxisx.settextcolor (Color.White);//Set Font Color//axisx.setname ("date"); //Table nameAxisx.settextsize (10);//Set Font sizeAxisx.setmaxlabelchars (8);//up to a few x-axis coordinates, meaning your scaling gives the number of data on the x-axis 7<=x<=maxisxvalues.lengthAxisx.setvalues (maxisxvalues);//fill the X-axis coordinate nameData.setaxisxbottom (AxisX);//x-axis at bottom//data.setaxisxtop (AxisX); //x-axis at topAxisx.sethaslines (true);//x-axis split line//The y-axis automatically sets the upper y-axis based on the size of the data (I'll give a solution to the number of y-axis data below)Axis Axisy =NewAxis ();//Y-AxisAxisy.setname ("");//Y-Axis calloutAxisy.settextsize (10);//Set Font sizeData.setaxisyleft (Axisy);//y-Axis set to left//data.setaxisyright (Axisy); //y-Axis set to the right//set behavior properties to support zooming, swiping, and panningLinechart.setinteractive (true);          Linechart.setzoomtype (zoomtype.horizontal); Linechart.setmaxzoom ((float) 2);//Maximum method ScaleLinechart.setcontainerscrollenabled (true, Containerscrolltype.horizontal);          Linechart.setlinechartdata (data);        Linechart.setvisibility (view.visible); /**Note: The following 7, 10 only represents a number to the analogy * was to solve the x-axis fixed data number. See (Http://forum.xda-developers.com/tools/programming/library-hellocharts-charting-library-t2904456/page2); */Viewport v=NewViewport (Linechart.getmaximumviewport ()); V.left= 0; V.right= 7;     Linechart.setcurrentviewport (v); }

Set the number of x-axis data displays:

New Viewport (Linechart.getmaximumviewport ());            = 0;           V.right= 7;           
   These 4 lines of code can set the x-axis data display number (x-axis 0-7 data  ),1    when the number of points is less than (), reduced to the extreme Hellochart default is all display.   2    when the number of points is greater than (),         2.1  if not set Axisx.setmaxlabelchars (int  count) This sentence, The x-axis is automatically adapted to the best possible number of data to display.        2.2  If set axisx.setmaxlabelchars (int  count) This sentence, 33 data point test,             2.2.1  if Axisx.setmaxlabelchars (10); The inside of the 10 is greater than v.right= 7,7, the first x-axis display 7 data, and then scale the number of x-axis is guaranteed to be            greater than 7 lessthan 2.2.2  if less than v.right= 7; Anyway, I feel like these two sentences have failed to look like--! If the V.right = 7                     is not set here, the chart will display all the data as far as possible at the beginning, and the interactivity is too poor.

Solutions for fixing the number of Y-axes from 0-100:

New Axis (). Sethaslines (true); Axisy.setmaxlabelchars (6); // Max label length, for example New Arraylist<>();  for (int i = 0; i <; i+=) {    new  axisvalue (i);     = "";    Value.setlabel (label);    Values.add (value);} Axisy.setvalues (values);

At the end of the line, you just have to divide the data by proportion.

The experience of using hellocharts bag

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.