Xcl-charts powerful dashboard

Source: Internet
Author: User

The dashboard in xcl-charts is one of the most troublesome diagrams I encapsulate. The reason is that people who have used it all know that this type of graph is too special. It is not easy to encapsulate it for most cases.

Fortunately, after a hard work, we finally developed a set of methods that we felt okay.

First, the following results are displayed:

Okay.

This type of chart is encapsulated separately. From the perspective of the overall layout, it can be divided into dashboards of different angles, such as 180,270 and 90,360. From the content perspective, there are two main difficulties: Various loops and various pointers.

You should observe the loop and pointer in the demo to understand the number of classes.

During encapsulation, I divided the rings of different styles into eight categories to plot and process most of the ring styles. Then, you can use the attributes to draw a picture suitable for your own needs.

Because there are too many categories, I will not illustrate how each circular axis is displayed.

As for pointers, as shown in the demo, I am hereDemonstrate several pointers of different styles and how to display multiple pointers in combination. This certainly does not include all of them. It is set through the combination of attributes and the combination with the annular axis.

You can customize various types of pointers.Because the basic calculation and drawing element chart library has been set up and opened up. So you don't have to worry about not drawing a proper pointer.

Pointers are one of the main issues that come back to us. The demo contains various types of graphs. Do I encapsulate each of them in the chart library independently?

Of course, the answer is no. My solution is as follows:

As mentioned earlier,I encapsulated eight types of axis styles. When drawing, you can decide which axes to add and where to display them.

My method is obvious. I give all the decisions to the user, and use the user's own add, and then use the relevant axis attribute settings to draw their own satisfactory results.

How much creativity they have can be drawn in a free combination.

Oh, forget, there is anotherDisplay of text in a dashboard. You often need to customize different texts. For this,My solution is to give the decision to the user.

After you have set the text and the paint brush attribute, you can specify the display position. How can this problem be solved?, My demo has proved.


It is useless to say so much. I will show the code of the example of the mixed graph (including the 270,180, 90 dashboard and the add method for different axes) in the demo above.

/*** Copyright 2014 xcl-charts *** licensed under the Apache license, version 2.0 (the "License"); * you may not use this file before t in compliance with the license. * You may be obtain a copy of the license at ** http://www.apache.org/licenses/LICENSE-2.0 ** unless required by applicable law or agreed to in writing, software * distributed under the license is distributed on an "as is" basis, * Without warranties or conditions of any kind, either express or implied. * See the license for the specific language governing permissions and * limitations under the license. ** @ project xcl-charts * @ description Android chart base class library demonstration * @ author xiongchuanliang <br/> ([email protected]) * @ license http://www.apache.org/licenses/ Apache V2 license * @ version 1.3 */package COM. demo. xclcharts. view; import Java. util. arraylist; import Java. util. list; import Org. xclcharts. chart. dialchart; import Org. xclcharts. common. densityutil; import Org. xclcharts. common. mathhelper; import Org. xclcharts. renderer. xenum; import android. content. context; import android. graphics. canvas; import android. graphics. color; import android. graphics. paint; import android. graphics. paint. align; import android. graphics. paint. style; import android. util. attributeset; import android. util. log; public class dialchart07view extends graphicalview {private string tag = "dialchart07view"; private dialchart chart = new dialchart (); Private dialchart chart180 = new dialchart (); private dialchart chart90 = new dialchart (); Private float mpercentage = 0.9f; Public dialchart07view (context) {super (context); // todo auto-generated constructor stubinitview ();} public dialchart07view (context, attributeset attrs) {super (context, attrs); initview ();} public dialchart07view (context, attributeset attrs, int defstyle) {super (context, attrs, defstyle); initview ();} private void initview () {chartrender (); chartrender90 (); chartrender180 () ;}@ override protected void onsizechanged (int w, int H, int oldw, int oldh) {super. onsizechanged (W, H, oldw, oldh); chart. setchartrange (W, H); chart180.setchartrange (W/2, H/3); chart90.setchartrange (W, H/3);} public void chartrender () {try {chart. setpadding (0, densityutil. dip2px (getcontext (), 100), 0, 0); // set the title background chart. setapplybackgroundcolor (true); chart. setbackgroundcolor (INT) color. RGB (28,129,243); // draw a border chart. showroundborder (); chart. settotalangle (270f); // sets the current percentage chart. getpointer (). setpercentage (mpercentage); // set the pointer length chart. getpointer (). setlength (0.65f, 0.2f); // Add the bearing addaxis (); //////////////////////////////////////// /// // Add the pointer addpointer (); // set the Additional Information addattrinfo (); //////////////////////////////////////// /// //} catch (exception E) {// todo auto-generated catch blocklog. E (TAG, E. tostring () ;}} public void chartrender180 () {try {chart180.settotalangle (180f); chart180.setstartangle (180f); // set the current percentage chart180.getpointer (). setpercentage (mpercentage); // set the pointer length chart180.getpointer (). setpointerstyle (xenum. pointerstyle. triangle); chart180.getpointer (). setlength (0.65f, 0.2f); List <float> ringpercentage = new arraylist <float> (); float rper = mathhelper. getinstance (). div (1, 4); // equivalent to 40% // 270, 4ringpercentage. add (rper); ringpercentage. add (rper); ringpercentage. add (rper); ringpercentage. add (rper); List <integer> rcolor = new arraylist <integer> (); rcolor. add (INT) color. RGB (242,110,131); rcolor. add (INT) color. RGB (238,204, 71); rcolor. add (INT) color. RGB (42,231,250); rcolor. add (INT) color. RGB (140,196, 27); chart180.addstrokeringaxis (0.75f, 0.6f, ringpercentage, rcolor); chart180.getplotaxis (). get (0 ). getfillaxispaint (). setcolor (INT) color. RGB (28,129,243); paint painttb = new paint (); painttb. setcolor (color. white); painttb. settextalign (align. center); painttb. settextsize (22); painttb. setantialias (true); chart180.addattributeinfo (xenum. location. bottom, "180 degree dashboard", 0.5f, painttb);} catch (exception e) {// todo auto-generated catch blocklog. E (TAG, E. tostring () ;}} public void chartrender90 () {try {chart90.setpadding (densityutil. dip2px (getcontext (), 150), 0, 0, 0); chart90.settotalangle (90f); chart90.setstartangle (270f); List <float> ringpercentage = new arraylist <float> (); float rper = mathhelper. getinstance (). div (1, 2); // equivalent to 40% // 270, 4ringpercentage. add (rper); ringpercentage. add (rper); List <integer> rcolor = new arraylist <integer> (); rcolor. add (INT) color. RGB (242,110,131); rcolor. add (INT) color. RGB (238,204, 71); chart90.addstrokeringaxis (0.75f, 0.6f, ringpercentage, rcolor); chart90.getplotaxis (). get (0 ). getfillaxispaint (). setcolor (INT) color. RGB (28,129,243); chart90.getpointer (). setlength (0.65f); paint painttb = new paint (); painttb. setcolor (color. white); painttb. settextalign (align. center); painttb. settextsize (22); painttb. setantialias (true); chart90.addattributeinfo (xenum. location. bottom, "90 degree dashboard", 0.5f, painttb);} catch (exception e) {// todo auto-generated catch blocklog. E (TAG, E. tostring () ;}} public void addaxis () {list <string> rlabels2 = new arraylist <string> (); For (INT I = 0; I <7; I ++) {rlabels2.add (integer. tostring (I * 10);} chart. addinnerticksaxis (0.7f, rlabels2); chart. getplotaxis (). get (0 ). getaxispaint (). setcolor (color. white); chart. getplotaxis (). get (0 ). getaxispaint (). setstrokewidth (8); chart. getplotaxis (). get (0 ). gettickmarkspaint (). setcolor (color. white); chart. getplotaxis (). get (0 ). getticklabelpaint (). setcolor (color. white); List <string> rlabels3 = new arraylist <string> (); For (INT I = 0; I <5; I ++) {If (0 = I) {rlabels3.add ("");} elserlabels3.add (integer. tostring (I * 10);} chart. addouterticksaxis (0.8f, rlabels3); chart. getplotaxis (). get (1 ). getaxispaint (). setcolor (color. red); chart. getplotaxis (). get (1 ). getaxispaint (). setstrokewidth (5); chart. getpointer (). setpointerstyle (xenum. pointerstyle. triangle); chart. getpointer (). getpointerpaint (). setstrokewidth (3); chart. getpointer (). getpointerpaint (). setstyle (style. fill); chart. getpointer (). getpointerpaint (). setcolor (INT) color. RGB (242,110,131); chart. getpointer (). getbasecirclepaint (). setcolor (INT) color. RGB (238,204, 71); chart. getpointer (). setbaseradius (10f);} // Add the public void addpointer () {} private void addattrinfo () {paint painttb = new paint (); painttb. setcolor (color. white); painttb. settextalign (align. center); painttb. settextsize (22); painttb. setantialias (true); chart. addattributeinfo (xenum. location. bottom, "270-degree dashboard", 0.5f, painttb);} public void setcurrentstatus (float percentage) {mpercentage = percentage; // clear the chart. clearall (); chart90.clearall (); chart180.clearall (); // set the current percentage chart. getpointer (). setpercentage (mpercentage); addaxis (); // Add the pointer addpointer (); addattrinfo (); chartrender180 (); chartrender90 (); chart90.getpointer (). setpercentage (mpercentage); chart180.getpointer (). setpercentage (mpercentage);} @ overridepublic void render (canvas) {// todo auto-generated method stub try {chart. render (canvas); chart90.render (canvas); chart180.render (canvas);} catch (exception e) {log. E (TAG, E. tostring ());}}}

The code is messy, but the display function is sufficient.

Well, I don't want to talk about it. If you want to know more about it, go to GitHub or open-source China and check out the code.

Believe me, there is always something you need for this chart library.Hey.


Blog: http://blog.csdn.net/xcl168

Mail: [email protected]






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.