Skip to content

Commit 31dff04

Browse files
committed
Minor fixes.
2 parents 74fb504 + 1901fd8 commit 31dff04

File tree

4 files changed

+9
-171
lines changed

4 files changed

+9
-171
lines changed

MPChartExample/src/com/xxmassdeveloper/mpchartexample/BarChartActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ protected void onCreate(Bundle savedInstanceState) {
6363
mChart = (BarChart) findViewById(R.id.chart1);
6464
mChart.setOnChartValueSelectedListener(this);
6565

66+
mChart.setDrawBarShadow(true);
6667
mChart.setDrawValueAboveBar(true);
6768

6869
mChart.setDescription("");

MPChartLib/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
22
apply plugin: 'android-maven'
33

44
android {
5-
compileSdkVersion 19
5+
compileSdkVersion 21
66
buildToolsVersion '21.1.1'
77
// resourcePrefix 'mpcht'
88
defaultConfig {
99
minSdkVersion 8
10-
targetSdkVersion 19
10+
targetSdkVersion 21
1111
versionCode 1
1212
versionName '1.0'
1313

@@ -33,6 +33,6 @@ android {
3333

3434
dependencies {
3535
//compile fileTree(dir: 'libs', include: ['*.jar'])
36-
compile 'com.android.support:support-v4:19.+'
37-
compile 'com.nineoldandroids:library:2.4.+'
36+
//compile 'com.android.support:support-v4:19.+'
37+
//compile 'com.nineoldandroids:library:2.4.+'
3838
}

README.md

Lines changed: 4 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ Features
5252

5353
**Core features:**
5454
- Scaling on both axes (with touch-gesture, axes separately or pinch-zoom)
55-
- Dragging (with touch-gesture)
55+
- Dragging / Panning (with touch-gesture)
5656
- Finger drawing (draw values into the chart with touch-gesture)
5757
- Highlighting values (with customizeable popup-views)
58+
- Multiple / Separate Axes
5859
- Save chart to SD-Card (as image, or as .txt file)
59-
- Read .txt file chart-data
6060
- Predefined color templates
6161
- Legends (generated automatically, customizeable)
62-
- Labels (both x- and y-axis, customizeable)
62+
- Customizeable Axes (both x- and y-axis)
6363
- Animations (build up animations, on both x- and y-axis)
6464
- Limit lines (providing additional information, maximums, ...)
6565
- Fully customizeable (paints, typefaces, legends, colors, background, gestures, dashed lines, ...)
@@ -157,178 +157,15 @@ Getting Started
157157

158158
For getting started, rely on the **"MPChartExample"** folder and check out the examples in that project. The example project is also [**available in the Google PlayStore**](https://play.google.com/store/apps/details?id=com.xxmassdeveloper.mpchartexample).
159159

160-
Furthermore, here is some code to begin with.
160+
For a **detailed documentation**, please refer the [**Wiki**](https://github.com/PhilJay/MPAndroidChart/wiki).
161161

162-
**Setup:**
163-
164-
For using a <code>LineChart, BarChart, ScatterChart, CandleStickChart or PieChart </code>, define it in .xml:
165-
```xml
166-
<com.github.mikephil.charting.charts.LineChart
167-
android:id="@+id/chart"
168-
android:layout_width="match_parent"
169-
android:layout_height="match_parent" />
170-
```
171-
```java
172-
LineChart chart = (LineChart) findViewById(R.id.chart);
173-
```
174-
175-
or create it in code (and then **add it to a layout**):
176-
```java
177-
LineChart chart = new LineChart(Context);
178-
```
179-
180-
**Styling:**
181-
182-
- <code>setDescription(String desc)</code>: Set a description text that appears in the bottom right corner of the chart.
183-
- <code>setDescriptionTypeface(Typeface t)</code>: Sets the <code>Typeface</code> used for drawing the description text.
184-
- <code>setDrawYValues(boolean enabled)</code>: If set to true, the actual drawn values will be drawn next to the points, bars, or pie slices of the chart.
185-
- <code>setValuePaintColor(int color)</code>: Sets the color used for drawing the values if <code>setDrawYValues(...)</code> is enabled.
186-
- <code>setValueTypeface(Typeface t)</code>: Sets the <code>Typeface</code> used for drawing the values if <code>setDrawYValues(...)</code> is enabled.
187-
- <code>setValueFormatter(DecimalFormat format)</code>: Sets a new `DecimalFormat` object that will be used to format all values inside the chart. If nothing is set, formatting (digits) is done automatically.
188-
- <code>setPaint(Paint p, int which)</code>: Replaces the specified default <code>Paint</code> object with a new one. This method can be used to replace any predefined <code>Paint</code> object with an own <code>Paint</code> object and develop a completely personalized design.
189-
190-
**Getters and convenience:**
191-
- <code>public ChartData getDataCurrent()</code>: Returns the <code>ChartData</code> object the chart currently displays. It contains all information concerning the displayed values such as minimum and maximum values, value counts, value sums, ...
192-
- <code>public float getYChartMin()</code>: Returns the current minimum y-value that can be displayed by the chart - bottom line.
193-
- <code>public float getYChartMax()</code>: Returns the current maximum y-value that can be displayed by the chart - top line.
194-
- <code>public float getAverage()</code>: Returns the average value across all values the chart holds.
195-
- <code>public float getAverage(int type)</code>: Returns the average value for a specific DataSet type in the chart. This type is the type provided in the <code>DataSet</code> constructor.
196-
- <code>public PointF getCenter()</code>: Returns the center point of the chart in pixels.
197-
- <code>public Paint getPaint(int which)</code>: Returns the requested Paint object from the chart.
198-
199-
200-
**Gestures & Selecting:**
201-
202-
- <code>setTouchEnabled(boolean enabled)</code>: If set to ture, touch gestures (such as scaling and dragging) will be possible on the chart. NOTE: If touch-gestures are disabled, highlighting on touch is disabled as well. Default: true.
203-
- <code>setDragEnabled(boolean enabled)</code>: Enables/disables dragging for the chart.
204-
- <code>setScaleEnabled(boolean enabled)</code>: Enables/disables scaling for the chart.
205-
- <code>setOnChartValueSelectedListener(OnChartValueSelectedListener l)</code>: Sets a selection-listener to the chart that will generate callbacks when values are selected or unselected. The callback contains the selected values and their indices.
206-
- <code>setHighlightEnabled(boolean enabled)</code>: If set to true, highlighting/selecting values is possible on the chart. Default: true.
207-
- <code>public void highlightValues(Highlight[] highs)</code>: Highlights the specified entries in the chart.
208-
209162
**Other:**
210163
- <code>saveToGallery(String title)</code>: Saves the current chart state as an image to the gallery.
211164
- <code>saveToPath(String title, String pathOnSD)</code>: Saves the current chart state as an image to the specified path.
212165
- <code>setScaleMinima(float x, float y)</code>: Sets the minimum scale factors for x- and y-axis. If set for example to 3f, the user will not be able to fully zoom out.
213166
- <code>centerViewPort(int xIndex, float val)</code>: This method makes it possible to aim the center of the view (what you can see from the chart) to a specific position inside the chart, described by the index on the x-axis and the value on the y-axis. This also works very well in combination with the `setScaleMinima(...)` method.
214167
- <code>fitScreen()</code>: Resets all zooming and dragging and makes the chart fit exactly it's bounds.
215168

216-
**Adding data:**
217-
218-
If you want to add values (data) to the chart, it has to be done via the
219-
220-
```java
221-
setData(ChartData data);
222-
```
223-
method. The baseclass <code>ChartData</code> class encapsulates all data and information that is needed for the chart during rendering. For each type of chart, a different subclass of `ChartData` (e.g. `LineData`) exists that should be used for setting data for the chart. In the constructor, you can hand over an <code>ArrayList<? extends DataSet></code> as the values to display, and an additional <code>ArrayList</code> of <code>String</code> that will describe the labels on the x-axis. Example with the class `LineData` (extends `ChartData`), which is used for adding data to a `LineChart`:
224-
225-
```java
226-
public LineData(ArrayList<String> xVals, ArrayList<LineDataSet> sets) { ... }
227-
```
228-
229-
So, what is a <code>DataSet</code> and why do you need it? That is actually pretty simple. One <code>DataSet</code> object represents a group of entries (datatype <code>Entry</code>) inside the chart that belong together. It is designed to **logically separate different groups of values in the chart**. For each type of chart, a differnt object that extends `DataSet` (e.g. `LineDataSet`) exists that allows specific styling.
230-
231-
As an example, you might want to display the quarterly revenue of two different companies over one year in a `LineChart`. In that case, it would be recommended to create two different <code>LineDataSet</code> objects, each containing four values (one for each quarter). As an <code>ArrayList<String></code> to describe the labels on the x-axis, you would simply provide the four Strings "1.Q", "2.Q", "3.Q", "4.Q".
232-
233-
Of course, it is also possible to provide just one <code>LineDataSet</code> object containing all 8 values for the two companys.
234-
235-
So how to setup a <code>LineDataSet</code> object?
236-
```java
237-
public LineDataSet(ArrayList<Entry> yVals, String label) { ... }
238-
```
239-
240-
When looking at the constructor, it is visible that the <code>LineDataSet</code> needs an <code>ArrayList</code> of type <code>Entry</code> and a `String` used to describe the `LineDataSet` and as a label used for the `Legend`. Furthermore this label can be used to find the `LineDataSet` amongst other `LineDataSet` objects in the `LineData` object.
241-
242-
The <code>ArrayList</code> of type <code>Entry</code> encapsulates all values of the chart. A <code>Entry</code> object is an additional wrapper around a value and holds the value itself, and it's position on the x-axis (the index inside the <code>ArrayList</code> of <code>String</code> of the <code>LineData</code> object the value is mapped to):
243-
```java
244-
public Entry(float val, int xIndex) { ... }
245-
```
246-
247-
Putting it all together (example of two companies with quarterly revenue over one year):
248-
249-
At first, create the lists of type <code>Entry</code> that will hold your values:
250-
251-
```java
252-
ArrayList<Entry> valsComp1 = new ArrayList<Entry>();
253-
ArrayList<Entry> valsComp2 = new ArrayList<Entry>();
254-
```
255-
Then, fill the lists with <code>Entry</code> objects. Make sure the entry objects contain the correct indices to the x-axis. (of course, a loop can be used here, in that case, the counter variable of the loop could be the index on the x-axis).
256-
257-
```java
258-
Entry c1e1 = new Entry(100.000f, 0); // 0 == quarter 1
259-
valsComp1.add(c1e1);
260-
Entry c1e2 = new Entry(50.000f, 1); // 1 == quarter 2 ...
261-
valsComp1.add(c1e2);
262-
// and so on ...
263-
264-
Entry c2e1 = new Entry(120.000f, 0); // 0 == quarter 1
265-
valsComp2.add(c2e1);
266-
Entry c2e2 = new Entry(110.000f, 1); // 1 == quarter 2 ...
267-
valsComp2.add(c2e2);
268-
//...
269-
```
270-
271-
Now that we have our lists of <code>Entry</code> objects, the <code>LineDataSet</code> objects can be created:
272-
```java
273-
LineDataSet setComp1 = new LineDataSet(valsComp1, "Company 1");
274-
LineDataSet setComp2 = new LineDataSet(valsComp2, "Company 2");
275-
```
276-
Last but not least, we create a list of <code>DataSets</code> and a list of x legend entries and build our <code>ChartData</code> object:
277-
278-
```java
279-
ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();
280-
dataSets.add(setComp1);
281-
dataSets.add(setComp2);
282-
283-
ArrayList<String> xVals = new ArrayList<String>();
284-
xVals.add("1.Q"); xVals.add("2.Q"); xVals.add("3.Q"); xVals.add("4.Q");
285-
286-
LineData data = new LineData(xVals, dataSets);
287-
mLineChart.setData(data);
288-
```
289-
290-
**Setting colors:**
291-
292-
Since release [v1.4.0](https://github.com/PhilJay/MPAndroidChart/releases/tag/v1.4.0), the `ColorTemplate` object that was responsible for setting colors in previous releases is no longer needed. Nevertheless, it still holds all predefined color arrays (e.g. `ColorTemplate.VORDIPLOM_COLORS` and provides convenience methods for transforming colors from the resources (resource integers) into "real" colors.
293-
294-
Instead of the `ColorTemplate`, colors can now be specified directly via `DataSet` object, which allows separate styling for each `DataSet`.
295-
296-
In this short example, we have our two different `LineDataSet` objects representing the quarterly revenues of two companies (previously mentioned in the **Adding data** tutorial), for which we now want to set different colors.
297-
298-
What we want:
299-
300-
- the values of "Company 1" should be represented by four different variations of the color "red"
301-
- the values of "Company 2" should be represented by four different variations of the color "green"
302-
303-
This is what the code looks like:
304-
305-
```java
306-
LineDataSet setComp1 = new LineDataSet(valsComp1, "Company 1");
307-
308-
// sets colors for the dataset, resolution of the resource name to a "real" color is done internally
309-
setComp1.setColors(new int[] { R.color.red1, R.color.red2, R.color.red3, R.color.red4 }, Context);
310-
311-
LineDataSet setComp2 = new LineDataSet(valsComp2, "Company 2");
312-
setComp2.setColors(new int[] { R.color.green1, R.color.green2, R.color.green3, R.color.green4 }, Context);
313-
```
314-
315-
Besides that, there are many other ways for setting colors for a `DataSet`. Here is the full documentation:
316-
317-
- `setColors(int [] colors, Context c)`: Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. You can use "new int[] { R.color.red, R.color.green, ... }" to provide colors for this method. Internally, the colors are resolved using getResources().getColor(...).
318-
- `setColors(int [] colors)`: Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. Make sure that the colors are already prepared (by calling getResources().getColor(...)) before adding them to the DataSet.
319-
- `setColors(ArrayList<Integer> colors)`: Sets the colors that should be used fore this DataSet. Colors are reused as soon as the number of Entries the DataSet represents is higher than the size of the colors array. Make sure that the colors are already prepared (by calling getResources().getColor(...)) before adding them to the DataSet.
320-
- `setColor(int color)`: Sets the one and ONLY color that should be used for this DataSet. Internally, this recreates the colors array and adds the specified color.
321-
322-
`ColorTemplate` example:
323-
324-
```java
325-
LineDataSet set = new LineDataSet(...);
326-
set.setColors(ColorTemplate.VORDIPLOM_COLORS);
327-
```
328-
329-
If no colors are set for a `DataSet`, default colors are used.
330-
331-
332169
**Displaying / styling legends:**
333170

334171
By default, all chart types support legends and will automatically generate and draw a legend after setting data for the chart. If a legend should be drawn or not can be enabled/disabled using the

screenshots/ValueFormatter.jpg

13.1 KB
Loading

0 commit comments

Comments
 (0)