iOS折线图突出显示颜色

时间:2019-04-10 06:19:32

标签: ios swift ios-charts

我正在使用charts 3.2.2 iOS版本。我试图绘制折线图。在折线图中,只要用户点击值点,就会显示高亮线。有什么办法可以隐藏或更改此突出显示的线条颜色。我面临的另一个问题是气泡不会出现在第一个条目上。我在网上找到了很多解决方案,但对我没有用。任何帮助将不胜感激。

    scoreLineChart.legend.form = .none
    scoreLineChart.rightAxis.enabled = false

    scoreLineChart.xAxis.labelPosition = .bottom

    scoreLineChart.xAxis.drawGridLinesEnabled = false
    scoreLineChart.dragEnabled = false
    scoreLineChart.doubleTapToZoomEnabled = false

    scoreLineChart.xAxis.granularityEnabled = true
    scoreLineChart.xAxis.granularity = 1.0

    scoreLineChart.leftAxis.axisMinimum = 0
    scoreLineChart.leftAxis.axisMaximum = 100.0
    scoreLineChart.leftAxis.setLabelCount(5, force: true)

    scoreLineChart.xAxis.valueFormatter = valueFormatter
    scoreLineChart.xAxis.avoidFirstLastClippingEnabled = true
    scoreLineChart.pinchZoomEnabled = false
    let marker = BalloonMarker(color: UIColor(hex: "#58595b"),
                               font: UIFont(name: "Avenir-Heavy", size: 14)!,
                               textColor: .white,
                               insets: UIEdgeInsets(top: 8, left: 8, bottom: 20, right: 8))

    marker.chartView = scoreLineChart
    marker.minimumSize = CGSize(width: 80, height: 40)
    scoreLineChart.marker = marker

添加数据条目后

 let setOne = LineChartDataSet(values: lineChartEntry, label: "") //Here we convert lineChartEntry to a LineChartDataSet

    setOne.mode = .cubicBezier
    setOne.drawValuesEnabled = true

    setOne.lineWidth = 1
    setOne.circleRadius = 3
    setOne.drawCircleHoleEnabled = false
    setOne.valueFont = .systemFont(ofSize: 9)
    setOne.formLineWidth = 1
    setOne.formSize = 15

    setOne.setCircleColor(ChartColorTemplates.colorFromString("#ffcc1a29"))

    if !isSingelValue {
        setOne.setColor(ChartColorTemplates.colorFromString("#ffcc1a29"))
    }else {
        setOne.setColor(UIColor.clear)
    }

    let data = LineChartData(dataSet: setOne)

    data.addDataSet(setOne) //Adds the line to the dataSet
    scoreLineChart.xAxis.axisMinimum = 0
    scoreLineChart.data = data //finally - it adds the chart data to the chart and causes an update
    //        scoreLineChart.data?.setValueFormatter(valueFormatter)
    scoreLineChart.chartDescription?.text = "" // Here we set the description for the graph
    scoreLineChart.notifyDataSetChanged()

2 个答案:

答案 0 :(得分:1)

您只需要将drawHorizontalHighlightIndicatorEnabled drawVerticalHighlightIndicatorEnabled设置为false即可隐藏网格线。

    let set1 = ScatterChartDataSet(entries: values1, label: "DS 1")
    set1.drawHorizontalHighlightIndicatorEnabled = false
    set1.drawVerticalHighlightIndicatorEnabled = false

答案 1 :(得分:0)

有什么办法可以隐藏或更改此突出显示线的颜色。

要显示/隐藏或更改突出显示的线条颜色,请编辑ChartDateSet的属性

let setOne = LineChartDataSet(values: lineChartEntry, label: "")
setOne.highlightColor = .red // color of the line
setOne.highlightWidht = 2.0 // width of the line
setOne.drawHorizontalHighlightIndicatorEnabled = false // hide horizontal line
setOne.drawVerticalHighlightIndicatorEnabled = false // hide vertical line

我面临的另一个问题是气泡不会出现在第一个条目上。

可悲的是,我无法使用Charts github存储库中的BallonMarker.swift重现此问题。而且不清楚您提供的图像中的第一个数据条目是哪个。

我尝试在图表中添加“第一个条目”,但BallonMarker可以正常工作。

enter image description here