1

I'm trying to create a bar chart using MP android bar chart.

I'm trying to create two entries in one xAxis. But when I do the outcome will be like the following:

enter image description here

As you can see the orange one is overlaying the pink one. I would like them to be side by side In the first xAxis.

The code for this is the following:

barList = ArrayList()
        barList.add(BarEntry(1f, listOfIncome[0].toFloat()))
        barList.add(BarEntry(1f, 15.0f))
        barList.add(BarEntry(3f, listOfIncome[1].toFloat()))
        barList.add(BarEntry(4f, listOfIncome[2].toFloat()))
        barList.add(BarEntry(5f, listOfIncome[3].toFloat()))
        val xAxis: XAxis = barChart.xAxis
        xAxis.setLabelCount(4)
        xAxis.axisLineWidth=2f
        lineDataSet = BarDataSet(barList, "Week")
        barData = BarData(lineDataSet)
        lineDataSet.setColors(ColorTemplate.JOYFUL_COLORS, 250)
        lineDataSet.barBorderWidth=5f
        barChart.data = barData
        barChart.contentDescription =
            "This Graph represent the expenses and income of the 11's month"
        barChart.setFitBars(true)
        lineDataSet.valueTextColor = Color.BLACK
        lineDataSet.valueTextSize = 15f

The variables are as followed:

Bar List:ArrayList<BarEntry>
barData:BarData
lineDataSet:BarDataSet
barChart:BarChart

I would like to know what am I missing here and why its overlaying like that and not creating it side by side in the same xAxis...

One more thing I forgot to mention :

If I do so it will add me another column (5) as you can see at the end but I would like it to be just 4 columns at total. (I thought i defined it in the setLabelCount but i see that it doesn't help..)

Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46
Ilan
  • 45
  • 3

0 Answers0