I am using MPAndroidChart library.
I wanted to use the CombinedChart
to create a Chart like that:
Is that possible? I tried it out but it doesnt seem to work because the entries arent working as i expected. You cant say an entry has value 2 on the x-axis and value 300 on the y-axis. Also i cant create two different y-axis, one for the bars and one for the lines.
Some curious thing is that MPAndroidChart first adds all x-values and after that all y-values and you have no possibility to controll which y-value belongs to which x-value because its just inserting the y-values in order of their appearing and relates it to the next x-value.
Is there some way how i can create such a diagram with MPAndroidChart. I actually dont want to be forced to use Google Charts because of the required internet connection (but creating that kind of diagram would work perfectly with Google Charts).
UPDATE: v3.0.0+
The example for the CombinedChart
has been extended, now allowing stacked bars and grouped bars together with other chart types.
The essence of setting data for a CombinedChart
is the CombinedData
class. It can be populated with various other data, such as LineData
, BarData
etc:
CombinedData data = new CombinedData();
data.setData(generateLineData()); // set LineData...
data.setData(generateBarData()); // set BarData...
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
chart.setData(data);
chart.invalidate();
How to create e.g. LineData can be found in the setting data documentation.
You can create a custom class that extends View and in onDraw method create Rectangles of the required height, width and position for bars. As for the lines well that's obvious, set the stroke to make it more visible.
I have used a custom View to create bars in my app WhiteMarker and lines in Chron.
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