【问题标题】:Line chart not getting displayed properly折线图未正确显示
【发布时间】:2019-05-17 17:36:20
【问题描述】:

我正在使用 Charts 库在我的应用程序中显示折线图。 出于某种原因,我使用 Carthage 方法将 Charts 框架集成到我的应用程序中。

但是,当只有两个点可用时,图表无法正确显示,否则点会正确显示。

我也在这个平台上研究过类似的问题,但没有运气。不知道为什么会这样?

请参阅下面的附加屏幕截图。提前致谢。

两点图表会显示如下 -

具有三个或更多点的图表将显示如下 -

【问题讨论】:

标签: ios swift charts carthage


【解决方案1】:

检查一下..

import UIKit
import Charts

class LineChartViewController: UIViewController, ChartViewDelegate{

    @IBOutlet weak var lineChartVw: LineChartView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.

        lineChartVw.delegate = self
        lineChartVw.chartDescription?.enabled = false
        lineChartVw.dragEnabled = true
        lineChartVw.setScaleEnabled(true)
        lineChartVw.pinchZoomEnabled = true
        lineChartVw.legend.enabled = false
        lineChartVw.drawBordersEnabled = true

        self.setDataCount(Int(2), range: UInt32(5))

        lineChartVw.xAxis.drawGridLinesEnabled = true
        lineChartVw.leftAxis.drawGridLinesEnabled = true
        lineChartVw.rightAxis.drawGridLinesEnabled = true
        lineChartVw.rightAxis.drawLabelsEnabled = false
        lineChartVw.xAxis.labelPosition = .bottom

    }


    func setDataCount(_ count: Int, range: UInt32) {
        let values = (0..<count).map { (i) -> ChartDataEntry in
            return ChartDataEntry(x: Double(i), y: Double(i), icon:#imageLiteral(resourceName: "round1"))
        }

        let set1 = LineChartDataSet(values: values, label: "DataSet 1")
        set1.drawIconsEnabled = false
        set1.setColor(.black)
        set1.setCircleColor(.black)
        set1.lineWidth = 1
        set1.circleRadius = 3
        set1.valueFont = .systemFont(ofSize: 9)
        set1.drawFilledEnabled = true

        let data = LineChartData(dataSet: set1)

        lineChartVw.data = data
    }
}

【讨论】:

  • 感谢本的回复。这些点正确显示在图表中,只有该线下方的区域部分填充,其余一切正常。
  • 只需添加。 set1.drawFilledEnabled = true
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 2017-03-19
  • 2019-06-29
  • 2021-11-22
  • 1970-01-01
  • 2014-09-24
相关资源
最近更新 更多