Android Chart Control Williamchart User Guide

Source: Internet
Author: User
Tags getcolor

Williamchart is an Android chart control on GitHub, project address: Https://github.com/diogobernardino/WilliamChart

The chart control works well and is easy to use.

Referring to the sample program it provides, I have written a simpler charting program with the following steps:

1. Download the project from GitHub and import its library project into ADT;

2. Import its sample project into ADT;

3. Create your own project, reference the Library project, and copy the DataRetriever class from the sample project to the source code directory of the project;

4. Create a Chart_layout.xml code as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent "    android:o rientation= "vertical" >   <com.db.chart.view.linechartviewxmlns:chart= "http://schemas.android.com/apk/ Res-auto "android:id=" @+id/linechart "    android:layout_width=" match_parent "    android:layout_height=" 0DP "    android:layout_weight= "."    android:paddingtop= "15DP"    android:paddingbottom= "5DP"    android: paddingleft= "10DP"    android:paddingright= "10DP"    chart:chart_shadowdy= "1DP"    Chart:chart_ shadowradius= "1DP"    chart:chart_shadowcolor= "#80000000"    chart:chart_axiscolor= "@color/axis"    chart:chart_axisborderspacing= "0DP" ></com.db.chart.view.LineChartView></LinearLayout>

5. Create an activity class with the following code:

Package Com.example.wxb_example;import Com.db.chart.model.lineset;import Com.db.chart.model.point;import Com.db.chart.view.linechartview;import Com.db.chart.view.ycontroller;import Android.app.activity;import Android.graphics.color;import Android.os.bundle;public class Williamchartactivity extends Activity {//Linear chart control private Static Linechartview mlinechart;private final static string[] Mlabels = {"ANT", "GNU", "OWL", "APE", "COD", "YAK", "RAM", " JAY "}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate ( Savedinstancestate); Setcontentview (r.layout.chart_layout); Mlinechart = (Linechartview) findViewById ( R.id.linechart);  Lineset data;mlinechart.reset (); int nsets = 2;  Two lines int npoints = 5; 5 points for each line (int i = 0; i < nsets; i++) {data = new lineset (); for (int j = 0; J < Npoints; J + +) Data.addpoint (new Point ( MLABELS[J], Dataretriever.randvalue (0, ten));d Ata.setdots (Dataretriever.randboolean ()). Setdotscolor ( Color.parsecolor (DataretrievEr.getcolor (Dataretriever.randnumber (0,2))). Setdotsradius (Dataretriever.randdimen (4,7)). SetLineThickness ( Dataretriever.randdimen (3,8)). Setlinecolor (Color.parsecolor (Dataretriever.getcolor (i))). SetDashed ( Dataretriever.randboolean ()). Setsmooth (Dataretriever.randboolean ()); if (i = = 2) {//data.setfill (Color.parsecolor (" #3388c6c3 ")), int[] colors = {Color.parsecolor (" #3388c6c3 "), color.transparent};d ata.setgradientfill (colors, null);} if (Dataretriever.randboolean ()) data.setdotsstrokethickness (Dataretriever.randdimen (1,4)). SetDotsStrokeColor ( Color.parsecolor (Dataretriever.getcolor (Dataretriever.randnumber (0,2))); Mlinechart.adddata (data);} Mlinechart.setgrid (Dataretriever.randpaint ()). Setverticalgrid (Dataretriever.randpaint ()). SetHorizontalGrid ( Dataretriever.randpaint ())//.setthresholdline (2, Randpaint ()). Setylabels (YController.LabelPosition.NONE). Setyaxis (False). Setxlabels (Dataretriever.getxposition ()). Setxaxis (Dataretriever.randboolean ()). SetMaxAxisValue (2). Animate (Dataretriever.randanimatIon (NULL, npoints))//.show ();}} 

Note that this class refers to a copy of the DataRetriever class.

To run the project, the effect is as follows:



The effect can be further manipulated.

Android Chart Control Williamchart User Guide

Related Article

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.