Let’s we  create Graph in Android with the help of GraphView .
Step 1) First we create new project in Android studio Name is ” GraphViewExample”
then, download  the androidGraphView library jar file.
 GraphView-4.0.1.jar
#Important:- The jar file does not support xml integration

Step 2) Copy the .jar file and paste it into lib folder
GraphView

Step 3)  1-Go File tab and select Project Structure for lib dependency
GraphView_synchonize
2-Go Dependency  tab , select File dependency and add lib .jar file or press OK
GraphView_1

Step 4)  After that , Update”activity_main.xml”

[Code language=”xml”]

[/Code]

 

Step 5) Then , Update “MainActivity.java”
[Code language=”java”]GraphView graph = (GraphView) findViewById(R.id.graph);
BarGraphSeries series = new BarGraphSeries(new DataPoint[]{
new DataPoint(0, 5),
new DataPoint(2, 5),
new DataPoint(3, 0),
new DataPoint(4, 2),
new DataPoint(4, 6)
});
graph.addSeries(series);

// styling-add color
series.setValueDependentColor(new ValueDependentColor() {
@Override
public int get(DataPoint data) {
return Color.rgb((int) data.getX() * 255 / 4, (int) Math.abs(data.getY() * 255 / 6), 100);
}
});

series.setSpacing(50);

//draw values on top
series.setDrawValuesOnTop(true);
series.setValuesOnTopColor(Color.RED);
series.setValuesOnTopSize(50);

}[/Code]

 

Result-Screenshot_2016-02-29-12-22-16

Advertisements