Skip to content

Commit 23e0178

Browse files
authored
Merge pull request PhilJay#2825 from danielgindi/icons
Entry cons in all chart types
2 parents ccf6b7e + 144af7b commit 23e0178

35 files changed

+858
-85
lines changed
1.19 KB
Loading

MPChartExample/res/menu/bar.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleHighlight"
1014
android:title="Toggle Highlight">

MPChartExample/res/menu/bubble.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleHighlight"
1014
android:title="Toggle Highlight">

MPChartExample/res/menu/line.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleFilled"
1014
android:title="Toggle Filled">

MPChartExample/res/menu/pie.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Y-Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleXVals"
1014
android:title="Toggle X-Values">

MPChartExample/res/menu/radar.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleFilled"
1014
android:title="Toggle Filled">

MPChartExample/res/menu/scatter.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
android:id="@+id/actionToggleValues"
66
android:title="Toggle Values">
77
</item>
8+
<item
9+
android:id="@+id/actionToggleIcons"
10+
android:title="Toggle Icons">
11+
</item>
812
<item
913
android:id="@+id/actionToggleHighlight"
1014
android:title="Toggle Highlight">

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
153153
mChart.invalidate();
154154
break;
155155
}
156+
case R.id.actionToggleIcons: {
157+
for (IDataSet set : mChart.getData().getDataSets())
158+
set.setDrawIcons(!set.isDrawIconsEnabled());
159+
160+
mChart.invalidate();
161+
break;
162+
}
156163
case R.id.actionToggleHighlight: {
157164
if (mChart.getData() != null) {
158165
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
@@ -236,7 +243,12 @@ private void setData(int count, float range) {
236243
for (int i = (int) start; i < start + count + 1; i++) {
237244
float mult = (range + 1);
238245
float val = (float) (Math.random() * mult);
239-
yVals1.add(new BarEntry(i, val));
246+
247+
if (Math.random() * 100 < 25) {
248+
yVals1.add(new BarEntry(i, val, getResources().getDrawable(R.drawable.star)));
249+
} else {
250+
yVals1.add(new BarEntry(i, val));
251+
}
240252
}
241253

242254
BarDataSet set1;
@@ -249,6 +261,9 @@ private void setData(int count, float range) {
249261
mChart.notifyDataSetChanged();
250262
} else {
251263
set1 = new BarDataSet(yVals1, "The year 2017");
264+
265+
set1.setDrawIcons(false);
266+
252267
set1.setColors(ColorTemplate.MATERIAL_COLORS);
253268

254269
ArrayList<IBarDataSet> dataSets = new ArrayList<IBarDataSet>();

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
2626
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
2727
import com.github.mikephil.charting.utils.ColorTemplate;
28+
import com.github.mikephil.charting.utils.MPPointF;
2829
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
2930

3031
import java.util.ArrayList;
@@ -108,6 +109,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
108109
mChart.invalidate();
109110
break;
110111
}
112+
case R.id.actionToggleIcons: {
113+
for (IDataSet set : mChart.getData().getDataSets())
114+
set.setDrawIcons(!set.isDrawIconsEnabled());
115+
116+
mChart.invalidate();
117+
break;
118+
}
111119
case R.id.actionToggleHighlight: {
112120
if(mChart.getData() != null) {
113121
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
@@ -167,14 +175,14 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
167175
float val = (float) (Math.random() * range);
168176
float size = (float) (Math.random() * range);
169177

170-
yVals1.add(new BubbleEntry(i, val, size));
178+
yVals1.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
171179
}
172180

173181
for (int i = 0; i < count; i++) {
174182
float val = (float) (Math.random() * range);
175183
float size = (float) (Math.random() * range);
176184

177-
yVals2.add(new BubbleEntry(i, val, size));
185+
yVals2.add(new BubbleEntry(i, val, size, getResources().getDrawable(R.drawable.star)));
178186
}
179187

180188
for (int i = 0; i < count; i++) {
@@ -186,11 +194,16 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
186194

187195
// create a dataset and give it a type
188196
BubbleDataSet set1 = new BubbleDataSet(yVals1, "DS 1");
197+
set1.setDrawIcons(false);
189198
set1.setColor(ColorTemplate.COLORFUL_COLORS[0], 130);
190199
set1.setDrawValues(true);
200+
191201
BubbleDataSet set2 = new BubbleDataSet(yVals2, "DS 2");
202+
set2.setDrawIcons(false);
203+
set2.setIconsOffset(new MPPointF(0, 15));
192204
set2.setColor(ColorTemplate.COLORFUL_COLORS[1], 130);
193205
set2.setDrawValues(true);
206+
194207
BubbleDataSet set3 = new BubbleDataSet(yVals3, "DS 3");
195208
set3.setColor(ColorTemplate.COLORFUL_COLORS[2], 130);
196209
set3.setDrawValues(true);

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.github.mikephil.charting.data.CandleDataSet;
2222
import com.github.mikephil.charting.data.CandleEntry;
2323
import com.github.mikephil.charting.interfaces.datasets.ICandleDataSet;
24+
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
2425
import com.xxmassdeveloper.mpchartexample.notimportant.DemoBase;
2526

2627
import java.util.ArrayList;
@@ -92,6 +93,20 @@ public boolean onCreateOptionsMenu(Menu menu) {
9293
public boolean onOptionsItemSelected(MenuItem item) {
9394

9495
switch (item.getItemId()) {
96+
case R.id.actionToggleValues: {
97+
for (IDataSet set : mChart.getData().getDataSets())
98+
set.setDrawValues(!set.isDrawValuesEnabled());
99+
100+
mChart.invalidate();
101+
break;
102+
}
103+
case R.id.actionToggleIcons: {
104+
for (IDataSet set : mChart.getData().getDataSets())
105+
set.setDrawIcons(!set.isDrawIconsEnabled());
106+
107+
mChart.invalidate();
108+
break;
109+
}
95110
case R.id.actionToggleHighlight: {
96111
if(mChart.getData() != null) {
97112
mChart.getData().setHighlightEnabled(!mChart.getData().isHighlightEnabled());
@@ -171,11 +186,18 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
171186

172187
boolean even = i % 2 == 0;
173188

174-
yVals1.add(new CandleEntry(i, val + high, val - low, even ? val + open : val - open,
175-
even ? val - close : val + close));
189+
yVals1.add(new CandleEntry(
190+
i, val + high,
191+
val - low,
192+
even ? val + open : val - open,
193+
even ? val - close : val + close,
194+
getResources().getDrawable(R.drawable.star)
195+
));
176196
}
177197

178198
CandleDataSet set1 = new CandleDataSet(yVals1, "Data Set");
199+
200+
set1.setDrawIcons(false);
179201
set1.setAxisDependency(AxisDependency.LEFT);
180202
// set1.setColor(Color.rgb(80, 80, 80));
181203
set1.setShadowColor(Color.DKGRAY);

0 commit comments

Comments
 (0)