Skip to content

Commit 30e301f

Browse files
author
Robert Schmid
committed
Simple Horizontal bar chart example
1 parent ae428c2 commit 30e301f

5 files changed

Lines changed: 117 additions & 23 deletions

File tree

‎MPChartExample/AndroidManifest.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<activity android:name="LineChartActivity2"></activity>
2828
<activity android:screenOrientation="landscape" android:name="MultipleChartsActivity"></activity>
2929
<activity android:name="BarChartActivity"></activity>
30+
<activity android:name="HorizontalBarChartActivity"></activity>
3031
<activity android:name="PieChartActivity"></activity>
3132
<activity android:name="MultiLineChartActivity"></activity>
3233
<activity android:name="BarChartActivityMultiDataset"></activity>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent" >
5+
6+
<com.github.mikephil.charting.charts.HorizontalBarChart
7+
android:id="@+id/chart1"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:layout_above="@+id/seekBar1" />
11+
12+
<SeekBar
13+
android:id="@+id/seekBar2"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:layout_alignParentBottom="true"
17+
android:layout_alignParentLeft="true"
18+
android:layout_margin="8dp"
19+
android:layout_toLeftOf="@+id/tvYMax"
20+
android:layout_marginRight="5dp"
21+
android:max="200"
22+
android:paddingBottom="12dp" />
23+
24+
<SeekBar
25+
android:id="@+id/seekBar1"
26+
android:layout_width="match_parent"
27+
android:layout_height="wrap_content"
28+
android:layout_above="@+id/seekBar2"
29+
android:layout_margin="8dp"
30+
android:layout_marginBottom="35dp"
31+
android:layout_toLeftOf="@+id/tvXMax"
32+
android:layout_marginRight="5dp"
33+
android:max="500"
34+
android:paddingBottom="12dp" />
35+
36+
<TextView
37+
android:id="@+id/tvXMax"
38+
android:layout_width="50dp"
39+
android:layout_height="wrap_content"
40+
android:layout_alignBottom="@+id/seekBar1"
41+
android:layout_alignParentRight="true"
42+
android:text="500"
43+
android:layout_marginBottom="15dp"
44+
android:layout_marginRight="10dp"
45+
android:gravity="right"
46+
android:textAppearance="?android:attr/textAppearanceMedium" />
47+
48+
<TextView
49+
android:id="@+id/tvYMax"
50+
android:layout_width="50dp"
51+
android:layout_height="wrap_content"
52+
android:layout_alignBottom="@+id/seekBar2"
53+
android:layout_alignParentRight="true"
54+
android:text="500"
55+
android:layout_marginBottom="15dp"
56+
android:layout_marginRight="10dp"
57+
android:gravity="right"
58+
android:textAppearance="?android:attr/textAppearanceMedium" />
59+
60+
</RelativeLayout>

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class BarChartActivity extends DemoBase implements OnSeekBarChangeListener,
3737
OnChartValueSelectedListener {
3838

39-
private BarChart mChart;
39+
protected BarChart mChart;
4040
private SeekBar mSeekBarX, mSeekBarY;
4141
private TextView tvX, tvY;
4242

@@ -45,7 +45,7 @@ protected void onCreate(Bundle savedInstanceState) {
4545
super.onCreate(savedInstanceState);
4646
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
4747
WindowManager.LayoutParams.FLAG_FULLSCREEN);
48-
setContentView(R.layout.activity_barchart);
48+
setContentView(getLayout());
4949

5050
tvX = (TextView) findViewById(R.id.tvXMax);
5151
tvY = (TextView) findViewById(R.id.tvYMax);
@@ -123,6 +123,11 @@ protected void onCreate(Bundle savedInstanceState) {
123123
// mChart.setDrawLegend(false);
124124
}
125125

126+
protected int getLayout()
127+
{
128+
return R.layout.activity_barchart;
129+
}
130+
126131
@Override
127132
public boolean onCreateOptionsMenu(Menu menu) {
128133
getMenuInflater().inflate(R.menu.bar, menu);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
package com.xxmassdeveloper.mpchartexample;
3+
4+
import android.os.Bundle;
5+
6+
public class HorizontalBarChartActivity extends BarChartActivity
7+
{
8+
@Override
9+
protected void onCreate(Bundle savedInstanceState)
10+
{
11+
super.onCreate(savedInstanceState);
12+
13+
//FIXME: Bar Shadow is not yet supported
14+
mChart.setDrawBarShadow(false);
15+
}
16+
17+
@Override
18+
protected int getLayout()
19+
{
20+
return R.layout.activity_horizontalbarchart;
21+
}
22+
}

‎MPChartExample/src/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.java‎

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.xxmassdeveloper.mpchartexample.CandleStickChartActivity;
2727
import com.xxmassdeveloper.mpchartexample.CubicLineChartActivity;
2828
import com.xxmassdeveloper.mpchartexample.DynamicalAddingActivity;
29+
import com.xxmassdeveloper.mpchartexample.HorizontalBarChartActivity;
2930
import com.xxmassdeveloper.mpchartexample.InvertedLineChartActivity;
3031
import com.xxmassdeveloper.mpchartexample.LineChartActivity1;
3132
import com.xxmassdeveloper.mpchartexample.LineChartActivity2;
@@ -59,7 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {
5960

6061
objects.add(new ContentItem("Line Chart 1", "A simple demonstration of the linechart."));
6162
objects.add(new ContentItem("Line Chart 2", "Another simple demonstration of the linechart."));
62-
objects.add(new ContentItem("Bar Chart", "A simple demonstration of the bar chart."));
63+
objects.add(new ContentItem("Bar Chart", "A simple demonstration of the bar chart."));
64+
objects.add(new ContentItem("Horizontal Bar Chart", "A simple demonstration of the horizontal bar chart."));
6365
objects.add(new ContentItem("Pie Chart", "A simple demonstration of the pie chart."));
6466
objects.add(new ContentItem("Scatter Chart", "A simple demonstration of the scatter chart."));
6567
objects.add(new ContentItem("Stacked Bar Chart",
@@ -122,35 +124,39 @@ public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
122124
i = new Intent(this, LineChartActivity2.class);
123125
startActivity(i);
124126
break;
125-
case 2:
126-
i = new Intent(this, BarChartActivity.class);
127-
startActivity(i);
128-
break;
129-
case 3:
127+
case 2:
128+
i = new Intent(this, BarChartActivity.class);
129+
startActivity(i);
130+
break;
131+
case 3:
132+
i = new Intent(this, HorizontalBarChartActivity.class);
133+
startActivity(i);
134+
break;
135+
case 4:
130136
i = new Intent(this, PieChartActivity.class);
131137
startActivity(i);
132138
break;
133-
case 4:
139+
case 5:
134140
i = new Intent(this, ScatterChartActivity.class);
135141
startActivity(i);
136142
break;
137-
case 5:
143+
case 6:
138144
i = new Intent(this, StackedBarActivity.class);
139145
startActivity(i);
140146
break;
141-
case 6:
147+
case 7:
142148
i = new Intent(this, AnotherBarActivity.class);
143149
startActivity(i);
144150
break;
145-
case 7:
151+
case 8:
146152
i = new Intent(this, MultiLineChartActivity.class);
147153
startActivity(i);
148154
break;
149-
case 8:
155+
case 9:
150156
i = new Intent(this, BarChartActivityMultiDataset.class);
151157
startActivity(i);
152158
break;
153-
case 9:
159+
case 10:
154160
// i = new Intent(this, DrawChartActivity.class);
155161
// startActivity(i);
156162

@@ -160,39 +166,39 @@ public void onItemClick(AdapterView<?> av, View v, int pos, long arg3) {
160166
b.setPositiveButton("OK", null);
161167
b.create().show();
162168
break;
163-
case 10:
169+
case 11:
164170
i = new Intent(this, SimpleChartDemo.class);
165171
startActivity(i);
166172
break;
167-
case 11:
173+
case 12:
168174
i = new Intent(this, ListViewBarChartActivity.class);
169175
startActivity(i);
170176
break;
171-
case 12:
177+
case 13:
172178
i = new Intent(this, ListViewMultiChartActivity.class);
173179
startActivity(i);
174180
break;
175-
case 13:
181+
case 14:
176182
i = new Intent(this, InvertedLineChartActivity.class);
177183
startActivity(i);
178184
break;
179-
case 14:
185+
case 15:
180186
i = new Intent(this, CandleStickChartActivity.class);
181187
startActivity(i);
182188
break;
183-
case 15:
189+
case 16:
184190
i = new Intent(this, CubicLineChartActivity.class);
185191
startActivity(i);
186192
break;
187-
case 16:
193+
case 17:
188194
i = new Intent(this, RadarChartActivitry.class);
189195
startActivity(i);
190196
break;
191-
case 17:
197+
case 18:
192198
i = new Intent(this, LineChartActivityColored.class);
193199
startActivity(i);
194200
break;
195-
case 18:
201+
case 19:
196202
i = new Intent(this, DynamicalAddingActivity.class);
197203
startActivity(i);
198204
break;

0 commit comments

Comments
 (0)