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 {
@Override
public void onvalueselected (int columnindex, int subcolumnindex,
Subcolumnvalue value) {
Generatelinedata (Value.getcolor (), 100);
}
@Override
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