XAxis write count is larger than it should be in iOS Charts 3.0.1 in Swift 3

I have two BarChartDataSets. One of them always has a size of 3, and the other is 2 or 3. I tested the code in version 3.0.0, and everything worked fine. When 3.0.1 came out, it broke my chart. I always have the correct number of bars, but I have six labels instead of 5, when the second dataset is only size 2. It has nothing to do with the stringForValueDelegate function . I set the values Xusing int, which are connected linearly with a bar, which I want to introduce in the index, so each column is distributed uniformly is working properly, but none of them has the same diversity, when I have 6 marks and 5 bars.

enter image description here The problem is shown on the left side, and what it looks like on the right when my BarChartDataSet is size 3. It duplicates any last value in the chart and adds it as the 6th label on the left. In 3.0.0, there would be only 5 shortcuts from left to left.

I delved into their code and where they create labels in XAxisRendererHorizontalBarChart.swift
right before their call

drawLabel()

I call

print("xAxis entries: \(xAxis.entries.count)")

which prints

xAxis entries: 6

on the console, although right before I call

let chartData = BarChartData(dataSets: [chartDataSet1, chartDataSet2])

I call

print("dataEntries1 count: \(dataEntries1.count), dataEntries2 count: (dataEntries2.count)")

prints

dataEntries1 count: 3, dataEntries2 count: 2

+4
source share
1 answer

Firstly, xAxis.entriesand dataSet.entriesquite different.

xAxis.entries - , , dataSet.entries - , , . .

x, min/max. 3.0 x y, x, y, computeAxisValues().

xAxis.entries dataSet.entries .

, x , , : setLabelCount(5(6), true):

open func setLabelCount(_ count: Int, force: Bool)
{
    self.labelCount = count
    forceLabelsEnabled = force
}

: labelCount, :

/// the number of label entries the axis should have
/// max = 25,
/// min = 2,
/// default = 6,
/// be aware that this number is not fixed and can only be approximated
open var labelCount: Int
{
    get
    {
        return _labelCount
    }
    set
    {
        _labelCount = newValue

        if _labelCount > 25
        {
            _labelCount = 25
        }
        if _labelCount < 2
        {
            _labelCount = 2
        }

        forceLabelsEnabled = false
    }
}
+2

Source: https://habr.com/ru/post/1662180/


All Articles