Skip to content

Commit

Permalink
Started working on legend. Did some refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilJay committed Jul 17, 2014
2 parents 259a803 + 1eac9da commit 13104b2
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 176 deletions.
Expand Up @@ -63,7 +63,7 @@ protected void onCreate(Bundle savedInstanceState) {

// disable 3D
mChart.set3DEnabled(false);
mChart.setYLegendCount(5);
mChart.setYLabelCount(5);

// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);
Expand Down Expand Up @@ -133,10 +133,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLegend(true);
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
Expand Down
Expand Up @@ -62,10 +62,12 @@ protected void onCreate(Bundle savedInstanceState) {

// disable 3D
mChart.set3DEnabled(false);
mChart.setYLegendCount(5);
mChart.setYLabelCount(5);

// scaling can now only be done on x- and y-axis separately
mChart.setPinchZoom(false);

mChart.setDrawLegend(false);

mSeekBarX.setProgress(45);
mSeekBarY.setProgress(100);
Expand Down Expand Up @@ -132,10 +134,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLegend(true);
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
Expand Down
Expand Up @@ -55,7 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
mChart.setDrawYValues(false);
mChart.setLineWidth(5f);
mChart.setCircleSize(5f);
mChart.setYLegendCount(6);
mChart.setYLabelCount(6);
mChart.setHighlightEnabled(true);

// if disabled, drawn datasets with the finger will not be automatically finished
Expand Down Expand Up @@ -141,13 +141,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
else
mChart.setAdjustXLegend(true);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
mChart.invalidate();
break;
}
case R.id.actionTogglePinch: {
if (mChart.isPinchZoomEnabled())
Expand Down
Expand Up @@ -2,6 +2,7 @@
package com.example.mpchartexample;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
Expand All @@ -11,8 +12,8 @@
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.BarLineChartBase.BorderStyle;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.ChartData;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
Expand All @@ -21,6 +22,7 @@
import com.github.mikephil.charting.interfaces.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.Highlight;
import com.github.mikephil.charting.utils.Legend;

import java.util.ArrayList;

Expand Down Expand Up @@ -86,7 +88,7 @@ protected void onCreate(Bundle savedInstanceState) {
// mChart.setDrawYLegend(false);

// set the number of y-legend entries the chart should have
mChart.setYLegendCount(6);
mChart.setYLabelCount(6);

// enable value highlighting
mChart.setHighlightEnabled(true);
Expand Down Expand Up @@ -117,6 +119,12 @@ protected void onCreate(Bundle savedInstanceState) {

// set the line to be drawn like this "- - - - - -"
mChart.enableDashedLine(10f, 5f, 0f);

int[] clrs = new int[] { Color.BLACK, Color.RED, Color.GREEN };
String[] labels = new String[] { "black", "red", "green" };

Legend l = new Legend(clrs, labels);
mChart.setLegend(l);

mSeekBarX.setProgress(45);
mSeekBarY.setProgress(100);
Expand Down Expand Up @@ -183,10 +191,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLegend(true);
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
Expand Down
Expand Up @@ -60,7 +60,7 @@ protected void onCreate(Bundle savedInstanceState) {

mChart.setLineWidth(5f);
mChart.setCircleSize(5f);
mChart.setYLegendCount(6);
mChart.setYLabelCount(6);

// enable value highlighting
mChart.setHighlightEnabled(true);
Expand Down Expand Up @@ -139,10 +139,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLegend(true);
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
Expand Down
Expand Up @@ -61,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) {

mChart.setOnChartValueSelectedListener(this);

mChart.setYLegendCount(6);
mChart.setYLabelCount(6);
mChart.setTouchEnabled(true);
mChart.setHighlightEnabled(true);
mChart.setDrawYValues(false);
Expand Down Expand Up @@ -120,10 +120,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleAdjustXLegend: {
if (mChart.isAdjustXLegendEnabled())
mChart.setAdjustXLegend(false);
if (mChart.isAdjustXLabelsEnabled())
mChart.setAdjustXLabels(false);
else
mChart.setAdjustXLegend(true);
mChart.setAdjustXLabels(true);

mChart.invalidate();
break;
Expand Down

0 comments on commit 13104b2

Please sign in to comment.