Aide ide tutorial - Add line graph

aide ide tutorial line graph or curve chart



Aide ide tutorial on how to add line graph in your project. A line graph or line plot or line graph or curve chart is a type of chart which displays information as a series of data points called 'markers' connected by straight line segments. It is a basic type of chart common in many fields.

Line graph coding:

first go to build.gradle and add this library.
compile 'com.github.lecho:hellocharts-library:1.5.8@aar'

Next goto your MainActivity.java and add this following codes:
import java.util.ArrayList;
import java.util.List;

import lecho.lib.hellocharts.model.Axis;
import lecho.lib.hellocharts.model.AxisValue;
import lecho.lib.hellocharts.model.Line;
import lecho.lib.hellocharts.model.LineChartData;
import lecho.lib.hellocharts.model.PointValue;
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.view.LineChartView;

LineChartView lineChartView;
String[] axisData = {"Jan", "Feb", "Mar", "Apr", "May"};
int[] yAxisData = {50, 20, 15, 30, 2};
lineChartView = (LineChartView)findViewById(R.id.chart);

List yAxisValues = new ArrayList();
List axisValues = new ArrayList();
Line line = new Line(yAxisValues).setColor(Color.parseColor("#9C27B0"));

        for (int i = 0; i < axisData.length; i++) {
            axisValues.add(i, new AxisValue(i).setLabel(axisData[i]));
        }

        for (int i = 0; i < yAxisData.length; i++) {
            yAxisValues.add(new PointValue(i, yAxisData[i]));
        }
List lines = new ArrayList();
        lines.add(line);

        LineChartData data = new LineChartData();
        data.setLines(lines);
        Axis axis = new Axis();
        axis.setValues(axisValues);
        axis.setTextSize(16);
axis.setName("Date");
        axis.setTextColor(Color.parseColor("#03A9F4"));
        data.setAxisXBottom(axis);

        Axis yAxis = new Axis();
        yAxis.setName("Percentage");
        yAxis.setTextColor(Color.parseColor("#03A9F4"));
        yAxis.setTextSize(16);
yAxis.setLineColor(Color. RED);
        data.setAxisYLeft(yAxis);

lineChartView.setLineChartData(data);
        Viewport viewport = new Viewport(lineChartView.getMaximumViewport());
        viewport.top = 110;
        lineChartView.setMaximumViewport(viewport);
lineChartView.setCurrentViewport(viewport);
And the last step is main.xml
<lecho.lib.hellocharts.view.LineChartView
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

Done, and run the codes.

Comments

Post a Comment

Leave a comment hdh

Popular posts from this blog

Implement in-app purchase in aide ide

Implement google admob interstitial ads in aide ide

Android listview with search function using aide ide

Implement google admob banner ads in aide ide


Malitanyo Developer blog & tutorial 2020
Refund Policy    Facebook Page    Google Play

Blogger.com