Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change the color of the highlight point #2334

Closed
mariaCP opened this issue Apr 6, 2017 · 4 comments
Closed

change the color of the highlight point #2334

mariaCP opened this issue Apr 6, 2017 · 4 comments

Comments

@mariaCP
Copy link

mariaCP commented Apr 6, 2017

Hello,
Is it possible change the color of the circle highlight point? Thank you!

@thierryH91200
Copy link
Contributor

thierryH91200 commented Apr 6, 2017

here's my logic
init array of circle Colors

      var circleColors = [NSUIColor]()
chartView.delegate = self

   func colorPicker(value : Double) -> NSUIColor {
   
        //input your own logic for how you actually want to color
        if value > 100 || value < 50 {
            return NSUIColor.red
        }
        else {
            return NSUIColor.black
        }
    }

    func setDataCount(_ count: Int, range: Double)
    {
        // MARK: ChartDataEntry
        var values = [ChartDataEntry]()
        var valueColors = [NSUIColor]()
      
        for i in 0..<count {
            let val: Double = Double(arc4random_uniform(UInt32(range)) + 3)
            values.append(ChartDataEntry(x: Double(i), y: val))
            valueColors.append(colorPicker(value: val))
            circleColors.append(colorPicker(value: val))
        }

        // MARK: LineChartDataSet
        var set1 = LineChartDataSet()
            set1 = LineChartDataSet(values: values, label: "DataSet 1")
            set1.circleRadius = 6.0
             
            set1.circleColors = circleColors
            set1.valueColors = valueColors
            
            set1.highlightLineDashLengths = [5.0, 2.5]
            set1.highlightColor = NSUIColor.black
            set1.highlightLineWidth = 2.0

            var dataSets = [LineChartDataSet]()
            dataSets.append(set1)
            
            // MARK: LineChartData
            let data = LineChartData(dataSets: dataSets)
            chartView.data = data
        }
}


the most important

// MARK: - ChartViewDelegate
extension LineChart1ViewController: ChartViewDelegate
{
    public func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight)
    {
        print("chartValueSelected : x = \(highlight.x) y = \(highlight.y)")
        
        var set1 = LineChartDataSet()
        set1 = (chartView.data?.dataSets[0] as? LineChartDataSet)!
        let values = set1.values
        let index = values.index(where: {$0.x == highlight.x})  // search index

        set1.circleColors = circleColors
        set1.circleColors[index!] = NSUIColor.cyan
        
        chartView.data?.notifyDataChanged()
        chartView.notifyDataSetChanged()
    }
    
    public func chartValueNothingSelected(_ chartView: ChartViewBase)
    {
        print("chartValueNothingSelected")

        var set1 = LineChartDataSet()
        set1 = (chartView.data?.dataSets[0] as? LineChartDataSet)!
        set1.circleColors = circleColors
        
        chartView.data?.notifyDataChanged()
        chartView.notifyDataSetChanged()
    }
}

capture d ecran 2017-04-06 a 18 25 33

@liuxuan30
Copy link
Member

@thierryH91200 thanks!

@VivekNahar
Copy link

How can we change icon image if we set icon in the place of the circle?

@gurpreet72060
Copy link

gurpreet72060 commented Apr 14, 2021

Hlo,
How can i auto select bar graph bar according to current month or day?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants