I am creating a CandleStick chart
from API: https://min-api.cryptocompare.com/data/histoday?fsym=BTC&tsym=USD&limit=10 Using Library: https://github.com/PhilJay/MPAndroidChart
When I creating the chart with the count of values as X-axis, There is no problem (ploat_point.add(new CandleEntry(i,high,low,open,close);
in for loop ).
But when I use ploat_point.add(new CandleEntry(time,high,low,open,close);
in for loop, And parse X-axis values using my custom function.
i.e :
xAxis = candle_chart.getXAxis();
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
Log.e(TAG, "getFormattedValue: " + (int) value);
return Utilities.timeStampToMonth((int) value + "");
}
});
This time it is showing the graph only when the paint style is set to Paint.Style.FILL_AND_STROKE
, But It does not increasing the bar size with candleDataSet.setBarSize()
. It depending only the candleDataSet.setShadowWidth()
.
my code :
private void drawCandleStickChart(JSONArray dataArr) throws JSONException {
mChart.setVisibility(View.GONE);
ArrayList<CandleEntry> plot_point = new ArrayList<>();
for (int i = 0; i < dataArr.length(); i++) {
JSONObject point = dataArr.getJSONObject(i);
int time = Math.round(Float.parseFloat(point.getString("time")));
float open = Float.parseFloat(String.valueOf(point.getString("open")));
float close = Float.parseFloat(String.valueOf(point.getString("close")));
float high = Float.parseFloat(String.valueOf(point.getString("high")));
float low = Float.parseFloat(String.valueOf(point.getString("low")));
plot_point.add(new CandleEntry(time, high, low, open, close));
}
CandleDataSet cds = new CandleDataSet(plot_point, "Entries");
cds.setShadowColor(Color.WHITE);
cds.setDecreasingColor(Color.RED);
cds.setDecreasingPaintStyle(Paint.Style.FILL_AND_STROKE);
cds.setIncreasingColor(Color.GREEN);
cds.setIncreasingPaintStyle(Paint.Style.FILL_AND_STROKE);
cds.setNeutralColor(Color.BLUE);
cds.setShowCandleBar(true);
cds.setBarSpace(0.5f);
cds.setShadowWidth(0.1f);
cds.setHighlightEnabled(false);
cds.setDrawValues(false);
candle_chart.setMaxVisibleValueCount(20);
CandleData cd = new CandleData(cds);
candle_chart.setData(cd);
candle_chart.invalidate();
candle_chart.setVisibility(View.VISIBLE);
}
I need X-axis as time and bar size is more than shadow please help me.