Giter Site home page Giter Site logo

jsuyash1514 / graph-kit Goto Github PK

View Code? Open in Web Editor NEW
25.0 4.0 5.0 12.25 MB

:bar_chart: Android library for plotting and editing graphs :chart_with_upwards_trend:

License: MIT License

Java 100.00%
graph graph-library android-library graph-plotter line-graph pie-chart bar-graphs edit-graph data-analysis graph-visualization graph-kit

graph-kit's Introduction

Graph Kit

Platform API License: MIT

This library allows you to plot different kinds of graphs from data points. The currently supported graphs are
Line Graph, Bar Graph and Pie Chart. This library also includes an EditGraphView which you can edit by dragging points
and also get normalized points from the curve.

Table of Content

Usage

Just add the following dependency in your app's build.gradle

dependencies {
      implementation 'com.mdgiitr.suyash:graphkit:0.9.0'
}

Features

Line Graph Usage

There are two ways you can use this Graph: through XML or Java.

XML

<com.mdgiitr.suyash.graphkit.LineGraph
        android:id="@+id/lineGraph"
        android:layout_width="700dp"
        android:layout_height="700dp"
        app:graph_color="#ff0000"
        app:label_text_size="25"
        app:line_thickness="8.0"
        app:scrollablex="true"/>    

Then use the View in your java file as follows:

LineGraph lineGraph = findViewById(R.id.lineGraph);

Java

You can use the following Java code to add the View in your desired layout.

LineGraph lineGraph = new LineGraph(getApplicationContext(),700,700); //Pass view width and view height as parameters
//Then add the view to your layout
layout.addView(lineGraph);

To add Data Points to your Line Graph create an ArrayList of DataPoints and add them as shown below:

        ArrayList<DataPoint> points = new ArrayList<>();
        points.add(new DataPoint(10,10));
        points.add(new DataPoint(100,50));
        points.add(new DataPoint(100,100));
        points.add(new DataPoint(150,200));
        lineGraph.setPoints(points);

Bar Graph Usage

There are two ways you can use this Graph: through XML or Java.

XML

<com.mdgiitr.suyash.graphkit.BarGraph
        android:layout_width="700dp"
        android:layout_height="700dp"
        android:id="@+id/barGraph"
        app:label_text_size="25" />
       

Then use the View in your java file as follows:

BarGraph barGraph = findViewById(R.id.barGraph);

Java

You can use the following Java code to add the View in your desired layout.

BarGraph barGraph = new BarGraph(getApplicationContext(),700,700); //Pass view width and view height as parameters
//Then add the view to your layout
layout.addView(barGraph);

To add Data to your Bar Graph create an ArrayList of DataPoint and add it as shown below:

        ArrayList<DataPoint> points = new ArrayList<>();
        points.add(new DataPoint("2014",5, Color.parseColor("#34495E")));
        points.add(new DataPoint("2015",9, Color.parseColor("#EC7063")));
        points.add(new DataPoint("2016",2, Color.parseColor("#2ECC71")));
        points.add(new DataPoint("2017",4, Color.parseColor("#F5B041")));
        barGraph.setPoints(points);

Pie Chart Usage

There are two ways you can use this Graph: through XML or Java.

XML

<com.mdgiitr.suyash.graphkit.PieChart
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:id="@+id/grid_pie"
       app:label_text_size="40"/>

Then use the View in your java file as follows:

PieChart pieChart = findViewById(R.id.pie_chart);

Java

You can use the following Java code to add the View in your desired layout.

PieChart pieChart = new PieChart(getApplicationContext(),700,700); //Pass view width and view height as parameters
//Then add the view to your layout
layout.addView(pieChart);

To add Data to your Pie Chart create an ArrayList of DataPoint and add it as shown below:

       ArrayList<DataPoint> points = new ArrayList<>();
       points.add(new DataPoint("Football",(float)40.1,Color.parseColor("#34495E")));
       points.add(new DataPoint("Cricket", (float)30.9, Color.parseColor("#EC7063")));
       points.add(new DataPoint("Basketball", (float)15.8,Color.parseColor("#2ECC71")));
       points.add(new DataPoint("Voleyball",(float)12.4,Color.parseColor("#F5B041")));
       pieChart.setPoints(points);

EditGraphView Usage

There are two ways you can use this Graph: through XML or Java.

XML

<com.mdgiitr.suyash.graphkit.EditGraphView
       android:id="@+id/editgraphview"
       android:layout_width="350dp"
       android:layout_height="350dp"
       android:layout_marginEnd="8dp"
       android:layout_marginStart="8dp"
       android:layout_marginTop="56dp"/>

Then use the View in your java file as follows:

final EditGraphView v = findViewById(R.id.editgraphview);

Java

You can use the following Java code to add the View in your desired layout.

EditGraphView v = new EditGraphView(this, 700, 700);//Pass view width and view height as parameters
 //Then add the view to your layout
layout.addView(pieChart);

API Documentation

LineGraph

Property Default values Java method Attribute Description
Data Points NA .setPoints(...) NA Data Points to plot
Scroll X false .setSCrollX(...) scrollablex Is the graph scrollable along the x-axis
Scroll Y false .setScrollY(...) scrollabley Is the graph scrollable alog the y-axis
Trace Color for Line Color.BLACK .setGraphColor(...) graph_color Set the color for tracing the line
Label Text Size 20 .setLabelTextSize(...) label_text_size Size of text used in the label markings
Grid Color Color.LTGRAY .setGridColor(...) grid_color Set the color of the grid lines created
Maximum number of divisions on each axis 50 .setMaxDivisions(...) max_divisions Set the maximum number of divisions on each axis

BarGraph

Property Default values Java method Attribute Description
Data Points NA .setPoints(...) NA Data Points to plot
Label Text Size 20 .setLabelTextSize(...) label_text_size Size of text used in the label markings
Space between two bars 10 .setSpace(...) bar_space Set the spacing between two bars

PieChart

Property Default values Java method Attribute Description
Data Points NA .setPoints(...) NA Data Points to plot
Label Text Size 40 .setLabelTextSize(...) label_text_size Size of text used in the label markings

EditGraphView

Property Default values Java method Attribute Description
Line Thickness 12 .lineThickness(...) line_thickness Data Points to plot
Line Color Color.BLACK .lineColor(...) graph_color Set the color for tracing the line
Get Y-coord from X-coord NA .getYFromX(...) NA Get Y-coord for a specific X between 0 and 1
Set Touch Tolerance 20 .setTouchTolerance(...) touch_tolerance Set Touch Tolerance for anchor points

Guidelines for Contributors

If you want to contribute to improve this library, please read our guidelines.

Possible Improvements

  • Line graph can be plotted for all 4 quadrants.
  • Zoom-in and zoom-out features can be added to graphs.
  • Number of curves can be plotted in a single line graph to compare between the plots or to find the intersections.
  • The Graphs can be made to plot in real-time.
  • Snapping feature can be added in EditGraphView.
  • Undo and Redo feature can be added in Edit graph.
  • Polar Coordinate system can be added.
  • Graphs can be plotted from functions and their roots, stationary points, integrals, etc. can be obtained from the graphs.
  • Database can be integrated to store the graphs locally in the app.

License

Graph Kit is licensed under MIT License. View license here.

graph-kit's People

Contributors

jsuyash1514 avatar karthikriyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graph-kit's Issues

App crashes when there are no data points

When a Bar Graph is defined in XML and if there are no points defined in onCreate() (i.e. barGraph.setPoints(points); is not set), it causes the app to be crashed without any logcat information. Hence, there is no possibility to define a plot in a layout initially and add the points dynamically through the app in a later stage.

Make Readme

Create a readme explaining all the features of v-1

Create a test-app

Use this library to create a user friendly test app implementing all the features of version v1

Bar Graph is not updating (Graph is not dynamic)

Hey Suyash,

If i try to change bar graph value second time then it's not updating, Initially it's creating graph and perfectly showing graph but when i try to update or change the value then it's not updating. For ex.

Initial Graph

BarGraph barGraph = findViewById(R.id.barGraph);
ArrayList<DataPoint> points = new ArrayList<>();

points.add(new DataPoint("Jan", 10, getResources().getColor(R.color.brown)));
points.add(new DataPoint("Feb", 5, getResources().getColor(R.color.brown)));

barGraph.setPoints(points);

While Updating Graph on click of button (which is not working)

BarGraph barGraph = findViewById(R.id.barGraph);
ArrayList<DataPoint> points = new ArrayList<>();

points.add(new DataPoint("Jan", 0, getResources().getColor(R.color.brown)));
points.add(new DataPoint("Feb", 3, getResources().getColor(R.color.brown)));

barGraph.setPoints(points);

Assign this issue to me so i can create pull request as i already fixed this issue

Add horizontal BarGraphs

The aim of this issue is to add horizontal bar graphs, where the Bars rest on the y axis, and the Values will be on the x axis.

Plot Line graph for all 4 quadrants.

Currently Line Graph supports only the first quadrant. We need to plot all the quadrants.

Approach would be something like this:

  • Based on the range of x and y, and the graph width and graph height calculate the location of the new origin
  • Shift each of the scaled points according to the new origin
  • For calculating the markers and their positions, a crude approach would be to begin from the origin and move on both opposite sides and set markers at intervals of the precalculated increments, inc1 and inc2. A better approach needs to be figured out.

Custom View and its dimensions from xml file

  • Return correct dimensions from xml file(Done)
  • Make line graph and bar graph scrollable.
  • Improvise the font size to make scales more visible.(Done)
  • Solve the dimension bug for pie chart. (Done)

Failed to resolve: com.mdgiitr.suyash:graphkit:0.9.0

I have added the dependency to the app but it always shows this error:

Execution failed for task ':app:checkDebugAarMetadata'.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Could not find com.mdgiitr.suyash:graphkit:0.9.0.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/mdgiitr/suyash/graphkit/0.9.0/graphkit-0.9.0.pom
- https://repo.maven.apache.org/maven2/com/mdgiitr/suyash/graphkit/0.9.0/graphkit-0.9.0.pom
Required by:
project :app

Possible solution:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.