Skip to content

Commit

Permalink
Merge pull request PhilJay#1670 from danielgindi/bar-border
Browse files Browse the repository at this point in the history
Bar border
  • Loading branch information
PhilJay committed Apr 11, 2016
2 parents 4ff32e5 + 9a3fd00 commit cd7635c
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 79 deletions.
4 changes: 4 additions & 0 deletions MPChartExample/res/menu/bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@
android:id="@+id/actionToggleAutoScaleMinMax"
android:title="Toggle auto scale min/max">
</item>
<item
android:id="@+id/actionToggleBarBorders"
android:title="Show Bar Borders">
</item>

</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down Expand Up @@ -179,17 +186,26 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
xVals.add((int) yVals1.get(i).getVal() + "");
}

BarDataSet set1 = new BarDataSet(yVals1, "Data Set");
set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
set1.setDrawValues(false);
BarDataSet set1;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setYVals(yVals1);
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "Data Set");
set1.setColors(ColorTemplate.VORDIPLOM_COLORS);
set1.setDrawValues(false);

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);

BarData data = new BarData(xVals, dataSets);
BarData data = new BarData(xVals, dataSets);

mChart.setData(data);
mChart.invalidate();
mChart.setData(data);
mChart.invalidate();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down Expand Up @@ -238,17 +245,26 @@ private void setData(int count, float range) {
yVals1.add(new BarEntry(val, i));
}

BarDataSet set1 = new BarDataSet(yVals1, "DataSet");
set1.setBarSpacePercent(35f);
BarDataSet set1;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setYVals(yVals1);
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "DataSet");
set1.setBarSpacePercent(35f);

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);

BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(mTf);
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(mTf);

mChart.setData(data);
mChart.setData(data);
}
}

@SuppressLint("NewApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlight: {
if(mChart.getData() != null) {
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
Expand Down Expand Up @@ -204,30 +211,43 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
yVals3.add(new BarEntry(val, i));
}

// create 3 datasets with different types
BarDataSet set1 = new BarDataSet(yVals1, "Company A");
// set1.setColors(ColorTemplate.createColors(getApplicationContext(),
// ColorTemplate.FRESH_COLORS));
set1.setColor(Color.rgb(104, 241, 175));
BarDataSet set2 = new BarDataSet(yVals2, "Company B");
set2.setColor(Color.rgb(164, 228, 251));
BarDataSet set3 = new BarDataSet(yVals3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
dataSets.add(set2);
dataSets.add(set3);

BarData data = new BarData(xVals, dataSets);
BarDataSet set1, set2, set3;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set2 = (BarDataSet)mChart.getData().getDataSetByIndex(1);
set3 = (BarDataSet)mChart.getData().getDataSetByIndex(2);
set1.setYVals(yVals1);
set2.setYVals(yVals2);
set3.setYVals(yVals3);
mChart.notifyDataSetChanged();
} else {
// create 3 datasets with different types
set1 = new BarDataSet(yVals1, "Company A");
// set1.setColors(ColorTemplate.createColors(getApplicationContext(),
// ColorTemplate.FRESH_COLORS));
set1.setColor(Color.rgb(104, 241, 175));
set2 = new BarDataSet(yVals2, "Company B");
set2.setColor(Color.rgb(164, 228, 251));
set3 = new BarDataSet(yVals3, "Company C");
set3.setColor(Color.rgb(242, 247, 158));

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
dataSets.add(set2);
dataSets.add(set3);

BarData data = new BarData(xVals, dataSets);
// data.setValueFormatter(new LargeValueFormatter());

// add space between the dataset groups in percent of bar-width
data.setGroupSpace(80f);
data.setValueTypeface(tf);

mChart.setData(data);
mChart.invalidate();
// add space between the dataset groups in percent of bar-width
data.setGroupSpace(80f);
data.setValueTypeface(tf);

mChart.setData(data);
mChart.invalidate();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down Expand Up @@ -216,16 +223,25 @@ private void setData(int count) {
xVals.add(i+"");
entries.add(mSinusData.get(i));
}

BarDataSet set = new BarDataSet(entries, "Sinus Function");
set.setBarSpacePercent(40f);
set.setColor(Color.rgb(240, 120, 124));

BarData data = new BarData(xVals, set);
data.setValueTextSize(10f);
data.setValueTypeface(mTf);
data.setDrawValues(false);
BarDataSet set;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set.setYVals(entries);
mChart.notifyDataSetChanged();
} else {
set = new BarDataSet(entries, "Sinus Function");
set.setBarSpacePercent(40f);
set.setColor(Color.rgb(240, 120, 124));

mChart.setData(data);
BarData data = new BarData(xVals, set);
data.setValueTextSize(10f);
data.setValueTypeface(mTf);
data.setDrawValues(false);

mChart.setData(data);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,27 @@ private void setData(List<Data> dataList) {
colors.add(green);
}

BarDataSet set = new BarDataSet(values, "Values");
set.setBarSpacePercent(40f);
set.setColors(colors);
set.setValueTextColors(colors);

BarData data = new BarData(dates, set);
data.setValueTextSize(13f);
data.setValueTypeface(mTf);
data.setValueFormatter(new ValueFormatter());

mChart.setData(data);
mChart.invalidate();
BarDataSet set;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set.setYVals(values);
mChart.notifyDataSetChanged();
} else {
set = new BarDataSet(values, "Values");
set.setBarSpacePercent(40f);
set.setColors(colors);
set.setValueTextColors(colors);

BarData data = new BarData(dates, set);
data.setValueTextSize(13f);
data.setValueTypeface(mTf);
data.setValueFormatter(new ValueFormatter());

mChart.setData(data);
mChart.invalidate();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down Expand Up @@ -235,16 +242,25 @@ private void setData(int count, float range) {
yVals1.add(new BarEntry((float) (Math.random() * range), i));
}

BarDataSet set1 = new BarDataSet(yVals1, "DataSet 1");
BarDataSet set1;

if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setYVals(yVals1);
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "DataSet 1");

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);

BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(tf);
BarData data = new BarData(xVals, dataSets);
data.setValueTextSize(10f);
data.setValueTypeface(tf);

mChart.setData(data);
mChart.setData(data);
}
}

@SuppressLint("NewApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.mikephil.charting.data.BarDataSet;
import com.github.mikephil.charting.data.BarEntry;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.data.filter.Approximator;
import com.github.mikephil.charting.data.filter.Approximator.ApproximatorType;
import com.github.mikephil.charting.highlight.Highlight;
Expand Down Expand Up @@ -140,6 +141,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down Expand Up @@ -194,18 +202,27 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
yVals1.add(new BarEntry(new float[] { val1, val2, val3 }, i));
}

BarDataSet set1 = new BarDataSet(yVals1, "Statistics Vienna 2014");
set1.setColors(getColors());
set1.setStackLabels(new String[] { "Births", "Divorces", "Marriages" });
BarDataSet set1;

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);
if (mChart.getData() != null &&
mChart.getData().getDataSetCount() > 0) {
set1 = (BarDataSet)mChart.getData().getDataSetByIndex(0);
set1.setYVals(yVals1);
mChart.notifyDataSetChanged();
} else {
set1 = new BarDataSet(yVals1, "Statistics Vienna 2014");
set1.setColors(getColors());
set1.setStackLabels(new String[]{"Births", "Divorces", "Marriages"});

ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();
dataSets.add(set1);

BarData data = new BarData(xVals, dataSets);
data.setValueFormatter(new MyValueFormatter());
BarData data = new BarData(xVals, dataSets);
data.setValueFormatter(new MyValueFormatter());

mChart.setData(data);
mChart.invalidate();
mChart.setData(data);
mChart.invalidate();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
mChart.notifyDataSetChanged();
break;
}
case R.id.actionToggleBarBorders: {
for (IBarDataSet set : mChart.getData().getDataSets())
((BarDataSet)set).setBarBorderWidth(set.getBarBorderWidth() == 1.f ? 0.f : 1.f);

mChart.invalidate();
break;
}
case R.id.actionToggleHighlightArrow: {
if (mChart.isDrawHighlightArrowEnabled())
mChart.setDrawHighlightArrow(false);
Expand Down
Loading

0 comments on commit cd7635c

Please sign in to comment.