android - Why is my graph not showing up? -
i trying use mpandroidchart library in project. how layout , activity code. not showing in layout when run this. sure i'm missing small. it? bugging me why not showing up
graph_activity.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin"> <com.github.mikephil.charting.charts.barchart android:id="@+id/chart" android:visibility="visible" android:layout_width="match_parent" android:layout_height="match_parent" /> </relativelayout>
graphtestactivity.java
public class graphtestactivity extends actionbaractivity { private linechart responsetimechart; @override public void oncreate(bundle savedinstancestate, persistablebundle persistentstate) { super.oncreate(savedinstancestate, persistentstate); setcontentview(r.layout.graph_activity); showbarchart(); } private void showbarchart() { barchart chart = (barchart) findviewbyid(r.id.chart); bardata data = new bardata(getxaxisvalues(), getdataset()); chart.setdata(data); chart.setdescription("my chart"); chart.animatexy(2000, 2000); chart.invalidate(); } private arraylist<bardataset> getdataset() { arraylist<bardataset> datasets = null; arraylist<barentry> valueset1 = new arraylist<>(); barentry v1e1 = new barentry(110.000f, 0); // jan valueset1.add(v1e1); barentry v1e2 = new barentry(40.000f, 1); // feb valueset1.add(v1e2); barentry v1e3 = new barentry(60.000f, 2); // mar valueset1.add(v1e3); barentry v1e4 = new barentry(30.000f, 3); // apr valueset1.add(v1e4); barentry v1e5 = new barentry(90.000f, 4); // may valueset1.add(v1e5); barentry v1e6 = new barentry(100.000f, 5); // jun valueset1.add(v1e6); arraylist<barentry> valueset2 = new arraylist<>(); barentry v2e1 = new barentry(150.000f, 0); // jan valueset2.add(v2e1); barentry v2e2 = new barentry(90.000f, 1); // feb valueset2.add(v2e2); barentry v2e3 = new barentry(120.000f, 2); // mar valueset2.add(v2e3); barentry v2e4 = new barentry(60.000f, 3); // apr valueset2.add(v2e4); barentry v2e5 = new barentry(20.000f, 4); // may valueset2.add(v2e5); barentry v2e6 = new barentry(80.000f, 5); // jun valueset2.add(v2e6); bardataset bardataset1 = new bardataset(valueset1, "brand 1"); bardataset1.setcolor(color.rgb(0, 155, 0)); bardataset bardataset2 = new bardataset(valueset2, "brand 2"); bardataset2.setcolors(colortemplate.colorful_colors); datasets = new arraylist<>(); datasets.add(bardataset1); datasets.add(bardataset2); return datasets; } private arraylist<string> getxaxisvalues() { arraylist<string> xaxis = new arraylist<>(); xaxis.add("jan"); xaxis.add("feb"); xaxis.add("mar"); xaxis.add("apr"); xaxis.add("may"); xaxis.add("jun"); return xaxis; } }
since version 22.1.0, class actionbaractivity
deprecated. should use appcompatactivity
.
maybe issue why not showing? sure issue related library? have added e.g. textview
.xml file , verified if showing?
Comments
Post a Comment