Using Hellocharts to draw a column chart

Source: Internet
Author: User

Download the dependent libraries first, with ready-made jar packages: Hellocharts-library-1.5.8.jar

Use directly in the layout you want:

< Lecho.lib.hellocharts.view.ColumnChartView Android:id = "@+id/columnchart" Android:layout_width = "Match_parent" Android:layout_height = "Match_parent" />

For example, draw data for one week:

Pseudo code:

Declaring the required variable
PublicFinalstaticnew string[] {"Jan", "Feb", "Mar", "APR", "may", "June" , "Jul", "the", "Sep", "Oct", "Nov", "Dec",}; Columnchartview Columnchart; Columnchartdata Columndata; ListNew arraylist<column>(); List<SubcolumnValue> Lsvalue;

Initialize the data and display it on the chart

private void Datainit () {

int numsubcolumns = 1;
int numcolumns = Months.length;

list<axisvalue> axisvalues = new arraylist<axisvalue> ();
list<column> columns = new arraylist<column> ();
List<subcolumnvalue> values;
for (int i = 0; i < NumColumns; ++i) {

values = new arraylist<subcolumnvalue> ();
for (int j = 0; j < Numsubcolumns; ++j) {
Values.add (new Subcolumnvalue (float) math.random () * 50f + 5,
Chartutils.pickcolor ()));
Click on the bar chart to show the amount of data
Axisvalues.add (New Axisvalue (i). SetLabel (Months[i]));

Columns.Add (values). Sethaslabelsonlyforselected (true));

Columndata = new Columnchartdata (columns);

Columndata.setaxisxbottom (New Axis (Axisvalues) Sethaslines (True)
. SetTextColor (Color.Black));
Columndata.setaxisyleft (New Axis (). Sethaslines (True)
. SetTextColor (Color.Black). Setmaxlabelchars (2));

Columnchart.setcolumnchartdata (Columndata);

Set value touch listener that would trigger changes for charttop.
Columnchart.setonvaluetouchlistener (New Valuetouchlistener ());

Set selection mode to keep selected month column highlighted.
Columnchart.setvalueselectionenabled (TRUE);

Columnchart.setzoomtype (zoomtype.horizontal);


* Bar Chart Listener
* @author 1017
Private class Valuetouchlistener Implements
Columnchartonvalueselectlistener {

public void onvalueselected (int columnindex, int subcolumnindex,
Subcolumnvalue value) {
Generatelinedata (Value.getcolor (), 100);

public void onvaluedeselected () {

Generatelinedata (chartutils.color_green, 0);


The final effect comes out:

Clicking on the corresponding histogram will show the data of the current item;

Using Hellocharts to draw a column chart

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: 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.