在x轴上显示最小/最大值

时间:2022-09-28 10:10:25

I am working with library. Anybody know if is it possible to force show min and max label on x-axis.

我在图书馆工作。有人知道是否有可能在x轴上强制显示最小值和最大值。

What I have:

我有什么:

在x轴上显示最小/最大值

What I want to achieve:

我想达到的目标:

在x轴上显示最小/最大值

My implementation:

我的实现:

private func prepareXAxis() {
    lineChart.xAxis.labelPosition = .bottom
    lineChart.xAxis.valueFormatter = ChartXAxisDateValueFormatter()
    lineChart.xAxis.labelFont = UIFont.pmd_robotoRegular(ofSize: 13.0)
    lineChart.xAxis.labelTextColor = UIColor.pmd_darkGrey
}

And implementation of my own ValueFormatter:

以及我自己的ValueFormatter的实现:

import Foundation
import Charts

class ChartXAxisDateValueFormatter: NSObject, IAxisValueFormatter {

    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "hh:mm\ndd MMM"

        return dateFormatter.string(from: Date(timeIntervalSince1970: value))
    }
}

Edit

I added this code but first and last label on x-axis is still skipped:

我添加了这个代码,但是x轴上的第一个和最后一个标签仍然被跳过:

lineChart.xAxis.axisMinimum = lineDataSet.xMin
lineChart.xAxis.axisMaximum = lineDataSet.xMax
lineChart.xAxis.avoidFirstLastClippingEnabled = false
lineChart.xAxis.granularity = 1.0

I checked lineDataSet.xMin and lineDataSet.xMax. They have valid values.

我查了lineDataSet。xMin lineDataSet.xMax。他们有有效值。

2 个解决方案

#1


1  

You need to set below property for not skip 1st and last value

您需要将属性设置为not skip 1和last值

//Set up XAxis into chart.
lineChart.xAxis.axisMinimum = 0
lineChart.xAxis.avoidFirstLastClippingEnabled = NO
lineChart.xAxis.granularity = 1.0

Hope this will helps.

希望这将帮助。

#2


0  

I found a solution. The lost line:

我找到了一个解决方案。丢失的线:

combinedChart.xAxis.forceLabelsEnabled = true

combinedChart.xAxis。forceLabelsEnabled = true

I also changed type of chart from LineChart to CombinedChartView.

我还将图表类型从LineChart更改为CombinedChartView。

#1


1  

You need to set below property for not skip 1st and last value

您需要将属性设置为not skip 1和last值

//Set up XAxis into chart.
lineChart.xAxis.axisMinimum = 0
lineChart.xAxis.avoidFirstLastClippingEnabled = NO
lineChart.xAxis.granularity = 1.0

Hope this will helps.

希望这将帮助。

#2


0  

I found a solution. The lost line:

我找到了一个解决方案。丢失的线:

combinedChart.xAxis.forceLabelsEnabled = true

combinedChart.xAxis。forceLabelsEnabled = true

I also changed type of chart from LineChart to CombinedChartView.

我还将图表类型从LineChart更改为CombinedChartView。