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

Changing color of the bar graph #2571

Closed
millerrob1000 opened this issue Jun 30, 2017 · 1 comment
Closed

Changing color of the bar graph #2571

millerrob1000 opened this issue Jun 30, 2017 · 1 comment

Comments

@millerrob1000
Copy link

Looked through the demo and didn't see a way to change the color of the bar graph part way though and then change it back. Basically I want to have the graph blue and then change to orange when a flag is triggered and then change back to blue.

Attached is an example of what I'm looking for.
simulator screen shot jun 30 2017 7 03 54 am

@thierryH91200
Copy link
Contributor

see #2334

 func setDataCount(_ count: Int, range: Double)
   {
       // MARK: BarChartDataEntry
       var yVals = [BarChartDataEntry]()
       for i in 0..<count
       {
           yVals.append(BarChartDataEntry(x: Double(i), y: Double(values[i])))
       }
       
       // MARK: BarChartDataSet
       var set1 = BarChartDataSet()
       if chartView.data == nil
       {
           set1 = BarChartDataSet(values: yVals, label: "DataSet")
           //set1.colors = ChartColorTemplates.vordiplom()
           set1.colors = [.orange, .orange, .orange, .orange, .orange, .orange, .orange]
           set1.drawValuesEnabled = false
           set1.stackLabels = ["Births"]
           
           var dataSets = [ChartDataSet]()
           
           dataSets.append(set1)
           
           // MARK: marker
           let  marker = YMarkerView( color: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1), font: NSUIFont.systemFont(ofSize: 12.0),
                                      textColor: NSUIColor.white,
                                      insets: EdgeInsets(top: 8.0, left: 8.0, bottom: 8.0, right: 8.0),
                                      yAxisValueFormatter: HourValueFormatter())
           
           marker.chartView = chartView
           marker.minimumSize = CGSize(width: 80.0, height: 40.0)
           chartView.marker = marker
           
           // MARK: BarChartData
           let data = BarChartData(dataSets: dataSets)
           chartView.fitBars = true
           
           chartView.data = data
       }
       else
       {
           set1 = (chartView.data!.dataSets[0] as! BarChartDataSet )
           set1.values = yVals
           
           chartView.data?.notifyDataChanged()
           chartView.notifyDataSetChanged()
       }
   }
   
    
   public func chartValueSelected(_ chartView: ChartViewBase, entry: ChartDataEntry, highlight: Highlight) {
       print("chartValueSelected : x = \(highlight.x)")
       
       var set1 = BarChartDataSet()
       set1 = (chartView.data?.dataSets[0] as? BarChartDataSet)!
       var color : [NSUIColor] = [.orange, .orange, .orange, .orange, .orange, .orange, .orange]
       color [Int(highlight.x) ] =  .blue
       set1.colors =  color
       
       chartView.data?.notifyDataChanged()
       chartView.notifyDataSetChanged()
       
   }
   public func chartValueNothingSelected(_ chartView: ChartViewBase)
   {
       print("chartValueNothingSelected")
       var set1 = BarChartDataSet()
       set1 = (chartView.data?.dataSets[0] as? BarChartDataSet)!
       
       set1.colors =  [.orange, .orange, .orange, .orange, .orange, .orange, .orange]
       
       chartView.data?.notifyDataChanged()
       chartView.notifyDataSetChanged()
       
   }

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

3 participants