MPAndroidChart - First and last bars not rendering correctly

后端 未结 4 667
南旧
南旧 2021-01-11 13:40
  1. In the bar chart I am creating the first and last rows are consistently being cut in half (even if I add additional bars). This also causes the values above the bar

相关标签:
4条回答
  • 2021-01-11 13:47

    Please use setAxisMinimum and setAxisMaximum, it will work perfectly!

    After your BarData is instantiated, you just need

    chart.getXAxis().setAxisMinimum(-data.getBarWidth() / 2);
    chart.getXAxis().setAxisMaximum(count-data.getBarWidth() / 2);`
    

    There is no need for setFitBars, and the count is BARENTRY size.

    0 讨论(0)
  • 2021-01-11 13:48

    If the problem is with the first bar only, you can use negative values for the axis minimum:

    xAxis.setAxisMinimum(-0.5f);
    

    Like in the answer to this question here:

    0 讨论(0)
  • 2021-01-11 14:01

    To answer your questions:

    1. In order to properly show your bars you need to fit the bars, like this (don't ask me why it's not enabled by default):

      chart.setFitBars(true)
      

      You can find more information in the BarChart javadocs:

      setFitBars(boolean enabled): Adds half of the bar width to each side of the x-axis range in order to allow the bars of the barchart to be fully displayed.

      If you have a CombinedChart you could use setSpaceMin() and setSpaceMax() to add additional spacing on both ends of the axis:

      XAxis xAxis = chart.getXAxis();
      xAxis.setSpaceMin(barData.getBarWidth() / 2f);
      xAxis.setSpaceMax(barData.getBarWidth() / 2f);
      
    2. It is currently impossible to infuence the value positions rendered on the axis. Creating a ValueFormatter only changes the displayed text, not the actual position of the label.

    0 讨论(0)
  • 2021-01-11 14:09

    i just fixed it,settings the x range min, using

      barChart.setFitBars(true);
      barChart.setVisibleXRangeMinimum(barEntries.size());
    
    0 讨论(0)
提交回复
热议问题