As the title says, I am trying to include MPAndroidChart in a project and cannot get the candles to show up. Here is my code:
List<CandleEntry> ceList = new ArrayList<>();
ceList.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));
ceList.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
ceList.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
ceList.add(new CandleEntry(3, 6f, 3.25f, 4.40f, 5.0f));
ceList.add(new CandleEntry(4, 5.57f, 2f, 2.80f, 4.5f));
CandleDataSet cds = new CandleDataSet(ceList, "Entries");
cds.setColor(Color.BLUE);
cds.setValueTextColor(Color.RED);
CandleData cd = new CandleData(cds);
candleStickChart.setData(cd);
candleStickChart.invalidate();
But I get this:

Chart Xml
<com.github.mikephil.charting.charts.CandleStickChart
android:id="@+id/CandleStickChart"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
The same code with a line chart seems to work fine. Any ideas what I could be doing wrong? Thanks!
Try to replace your code with following.
List<CandleEntry> ceList = new ArrayList<>();
ceList.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));
ceList.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
ceList.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
ceList.add(new CandleEntry(3, 6f, 3.25f, 4.40f, 5.0f));
ceList.add(new CandleEntry(4, 5.57f, 2f, 2.80f, 4.5f));
CandleDataSet cds = new CandleDataSet(ceList, "Entries");
cds.setColor(Color.rgb(80, 80, 80));
cds.setShadowColor(Color.DKGRAY);
cds.setShadowWidth(0.7f);
cds.setDecreasingColor(Color.RED);
cds.setDecreasingPaintStyle(Paint.Style.FILL);
cds.setIncreasingColor(Color.rgb(122, 242, 84));
cds.setIncreasingPaintStyle(Paint.Style.STROKE);
cds.setNeutralColor(Color.BLUE);
cds.setValueTextColor(Color.RED);
CandleData cd = new CandleData(cds);
candleStickChart.setData(cd);
candleStickChart.invalidate();
In this, you have to specify certain properties.
I think you must use under 1000 value for your x-axis I don't know why but when I try this solution my chart work like a charm if you want to add time for your x-axis you can divide your timestamp by 1000000000.0 and then in value formatter cross this value to your value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With