31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/WordPressGraphView/src/main/java/com/jjoe64/graphview/ValueDependentColor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of GraphView.
3 | *
4 | * GraphView is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * GraphView is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with GraphView. If not, see .
16 | *
17 | * Copyright Jonas Gehring
18 | */
19 |
20 | package com.jjoe64.graphview;
21 |
22 | /**
23 | * you can change the color depending on the value.
24 | * takes only effect in BarGraphView
25 | */
26 | public interface ValueDependentColor {
27 | public int get(GraphViewDataInterface data);
28 | }
29 |
--------------------------------------------------------------------------------
/WordPressGraphView/src/main/java/com/jjoe64/graphview/GraphViewDataInterface.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of GraphView.
3 | *
4 | * GraphView is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * GraphView is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with GraphView. If not, see .
16 | *
17 | * Copyright Jonas Gehring
18 | */
19 |
20 | package com.jjoe64.graphview;
21 |
22 | /**
23 | * the base interface for the graphview data.
24 | * you can use your own data models, when they implement
25 | * this interface.
26 | */
27 | public interface GraphViewDataInterface {
28 | public double getX();
29 | public double getY();
30 | }
31 |
--------------------------------------------------------------------------------
/WordPressGraphView/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:2.3.3'
7 | classpath 'com.novoda:bintray-release:0.5.0'
8 | }
9 | }
10 |
11 | apply plugin: 'com.android.library'
12 | apply plugin: 'maven'
13 | apply plugin: 'com.novoda.bintray-release' // must be applied after your artifact generating plugin (eg. java / com.android.library)
14 |
15 | repositories {
16 | jcenter()
17 | }
18 |
19 | android {
20 | publishNonDefault true
21 |
22 | compileSdkVersion 19
23 | buildToolsVersion "25.0.3"
24 |
25 | defaultConfig {
26 | versionName "3.4.1"
27 | versionCode 1
28 | minSdkVersion 8
29 | targetSdkVersion 19
30 | }
31 | }
32 |
33 | publish {
34 | artifactId = 'graphview'
35 | userOrg = 'wordpress-mobile'
36 | groupId = 'org.wordpress'
37 | uploadName = 'graphview'
38 | description = 'Android library for programmatic visual diagram creation'
39 | publishVersion = android.defaultConfig.versionName
40 | licences = ['LGPL-3.0']
41 | website = 'https://github.com/wordpress-mobile/GraphView'
42 | dryRun = 'false'
43 | autoPublish = 'true'
44 | }
45 |
--------------------------------------------------------------------------------
/doc/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Overview List
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/WordPressGraphView/src/main/java/com/jjoe64/graphview/CustomLabelFormatter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of GraphView.
3 | *
4 | * GraphView is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * GraphView is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with GraphView. If not, see .
16 | *
17 | * Copyright Jonas Gehring
18 | */
19 |
20 | package com.jjoe64.graphview;
21 |
22 | /**
23 | * if you want to show different labels,
24 | * you can use this label formatter.
25 | * As Input you get the raw value (x or y) and
26 | * you return a String that will be displayed.
27 | * {@code
28 | * graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
29 | public String formatLabel(double value, boolean isValueX) {
30 | if (isValueX) {
31 | if (value < 5) {
32 | return "small";
33 | } else if (value < 15) {
34 | return "middle";
35 | } else {
36 | return "big";
37 | }
38 | }
39 | return null; // let graphview generate Y-axis label for us
40 | }
41 | });
42 | * }
43 | */
44 | public interface CustomLabelFormatter {
45 |
46 | /**
47 | * will be called when the labels were generated
48 | * @param value the raw input value (x or y)
49 | * @param isValueX true if value is a x-value, false if otherwise
50 | * @return the string that will be displayed. return null if you want graphview to generate the label for you.
51 | */
52 | String formatLabel(double value, boolean isValueX);
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/WordPressGraphView/src/main/java/com/jjoe64/graphview/BarGraphView.java:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of GraphView.
3 | *
4 | * GraphView is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU Lesser General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * GraphView is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with GraphView. If not, see .
16 | *
17 | * Copyright Jonas Gehring
18 | */
19 |
20 | package com.jjoe64.graphview;
21 |
22 | import android.content.Context;
23 | import android.graphics.Canvas;
24 | import android.util.AttributeSet;
25 |
26 | import com.jjoe64.graphview.GraphViewSeries.GraphViewSeriesStyle;
27 |
28 | /**
29 | * Draws a Bar Chart
30 | * @author Muhammad Shahab Hameed
31 | */
32 | public class BarGraphView extends GraphView {
33 | public BarGraphView(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | public BarGraphView(Context context, String title) {
38 | super(context, title);
39 | }
40 |
41 | @Override
42 | protected void onBeforeDrawSeries() {
43 | }
44 |
45 | @Override
46 | public void drawSeries(Canvas canvas, GraphViewDataInterface[] values, float graphwidth, float graphheight,
47 | float border, double minX, double minY, double diffX, double diffY,
48 | float horstart, GraphViewSeriesStyle style) {
49 | float colwidth = (graphwidth - (2 * border)) / values.length;
50 |
51 | paint.setStrokeWidth(style.thickness);
52 | paint.setColor(style.color);
53 |
54 | // draw data
55 | for (int i = 0; i < values.length; i++) {
56 | float valY = (float) (values[i].getY() - minY);
57 | float ratY = (float) (valY / diffY);
58 | float y = graphheight * ratY;
59 |
60 | // hook for value dependent color
61 | if (style.getValueDependentColor() != null) {
62 | paint.setColor(style.getValueDependentColor().get(values[i]));
63 | }
64 |
65 | canvas.drawRect((i * colwidth) + horstart, (border - y) + graphheight, ((i * colwidth) + horstart) + (colwidth - 1), graphheight + border - 1, paint);
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Chart and Graph Library for Android
2 | ====================================
3 |
4 |
What is GraphView
5 | GraphView is a library for Android to programmatically create flexible and nice-looking diagramms. It is easy to understand, to integrate and to customize it.
6 | At the moment there are two different types:
7 |
19 |
20 | * Two chart types
21 | Line Chart and Bar Chart.
22 | * Draw multiple series of data
23 | Let the diagram show more that one series in a graph. You can set a color and a description for every series.
24 | * Show legend
25 | A legend can be displayed inline the chart. You can set the width and the vertical align (top, middle, bottom).
26 | * Custom labels
27 | The labels for the x- and y-axis are generated automatically. But you can set your own labels, Strings are possible.
28 | * Handle incomplete data
29 | It's possible to give the data in different frequency.
30 | * Viewport
31 | You can limit the viewport so that only a part of the data will be displayed.
32 | * Scrolling
33 | You can scroll with a finger touch move gesture.
34 | * Scaling / Zooming
35 | Since Android 2.3! With two-fingers touch scale gesture (Multi-touch), the viewport can be changed.
36 | * Background (line graph)
37 | Optionally draws a light background under the diagram stroke.
38 | * Manual Y axis limits
39 | * Realtime Graph (Live)
40 | * And more
41 |
42 |
85 | This API (Application Programming Interface) document has pages corresponding to the items in the navigation bar, described as follows.
86 | Package
87 |
88 |
89 |
90 | Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
91 |
Interfaces (italic)
Classes
Enums
Exceptions
Errors
Annotation Types
92 |
93 |
94 | Class/Interface
95 |
96 |
97 |
98 | Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
99 |
Class inheritance diagram
Direct Subclasses
All Known Subinterfaces
All Known Implementing Classes
Class/interface declaration
Class/interface description
100 |
101 |
Nested Class Summary
Field Summary
Constructor Summary
Method Summary
102 |
103 |
Field Detail
Constructor Detail
Method Detail
104 | Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
105 |
106 |
107 | Annotation Type
108 |
109 |
110 |
111 | Each annotation type has its own separate page with the following sections:
112 |
Annotation Type declaration
Annotation Type description
Required Element Summary
Optional Element Summary
Element Detail
113 |
114 |
115 |
116 | Enum
117 |
118 |
119 |
120 | Each enum has its own separate page with the following sections:
121 |
Enum declaration
Enum description
Enum Constant Summary
Enum Constant Detail
122 |
123 |
124 | Use
125 |
126 | Each documented package, class and interface has its own Use page. This page describes what packages, classes, methods, constructors and fields use any part of the given class or package. Given a class or interface A, its Use page includes subclasses of A, fields declared as A, methods that return A, and methods and constructors with parameters of type A. You can access this page by first going to the package, class or interface, then clicking on the "Use" link in the navigation bar.
127 |
128 | Tree (Class Hierarchy)
129 |
130 | There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting with java.lang.Object. The interfaces do not inherit from java.lang.Object.
131 |
When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
132 |
133 |
134 | Deprecated API
135 |
136 | The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
137 |
138 | Index
139 |
140 | The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
141 |
142 | Prev/Next
143 | These links take you to the next or previous class, interface, package, or related page.
144 | Frames/No Frames
145 | These links show and hide the HTML frames. All pages are available with or without frames.
146 |
147 |
148 | Serialized Form
149 | Each serializable or externalizable class has a description of its serialization fields and methods. This information is of interest to re-implementors, not to developers using the API. While there is no link in the navigation bar, you can get to this information by going to any serialized class and clicking "Serialized Form" in the "See also" section of the class description.
150 |
151 |
152 | Constant Field Values
153 | The Constant Field Values page lists the static final fields and their values.
154 |
155 |
156 |
157 | This help file applies to API documentation generated using the standard doclet.
158 |
159 |
160 |
100 | if you want to show different labels,
101 | you can use this label formatter.
102 | As Input you get the raw value (x or y) and
103 | you return a String that will be displayed.
104 | graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
105 | public String formatLabel(double value, boolean isValueX) {
106 | if (isValueX) {
107 | if (value < 5) {
108 | return "small";
109 | } else if (value < 15) {
110 | return "middle";
111 | } else {
112 | return "big";
113 | }
114 | }
115 | return null; // let graphview generate Y-axis label for us
116 | }
117 | });
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | Method Summary
133 |
134 |
135 |
136 | java.lang.String
137 |
formatLabel(double value,
138 | boolean isValueX)
139 |
140 |
141 | will be called when the labels were generated