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

drawHighlighted() not calling #1212

Closed
Prathame5h opened this issue Jul 2, 2016 · 4 comments
Closed

drawHighlighted() not calling #1212

Prathame5h opened this issue Jul 2, 2016 · 4 comments

Comments

@Prathame5h
Copy link

import UIKit
import Charts

class LineChartViewController: UIViewController, ChartViewDelegate {

@IBOutlet weak var lineChartView: LineChartView!

@IBOutlet weak var slider: UISlider!

@IBOutlet weak var lblSlider: UILabel!

let markerView = MarkerView(frame: CGRect(x: 0, y: 0, width: 80, height: 60))

var entryValue: String!

override func viewDidLoad() {
    super.viewDidLoad()
    lineChartView.delegate = self

    let days = ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10", "Day 11", "Day 12", "Day 13", "Day 14", "Day 15", "Day 16", "Day 17", "Day 18", "Day 19", "Day 20", "Day 21", "Day 22", "Day 23", "Day 24", "Day 25", "Day 26", "Day 27", "Day 28", "Day 29", "Day 30"]
    let unitsSold1 = [850.0, 800, 300, 1200, 800, 900, 1500]
    let unitsSold2 = [400.0, 600, 500, 0, 400, 300, 200]
    let unitsSold3 = [50.0, 0, 300, 0, 0, 0, 0]
    let unitsSold4 = [200.0, 0, 0, 300, 0, 0, 0]
    let unitsSold5 = [2400.0, 1000, 700, 0, 900, 400, 600]

    let rVal1 = unitsSold1[0] + unitsSold2[0] + unitsSold3[0] + unitsSold4[0] + unitsSold5[0]
    let rVal2 = unitsSold1[1] + unitsSold2[1] + unitsSold3[1] + unitsSold4[1] + unitsSold5[1]
    let rVal3 = unitsSold1[2] + unitsSold2[2] + unitsSold3[2] + unitsSold4[2] + unitsSold5[2]
    let rVal4 = unitsSold1[3] + unitsSold2[3] + unitsSold3[3] + unitsSold4[3] + unitsSold5[3]
    let rVal5 = unitsSold1[4] + unitsSold2[4] + unitsSold3[4] + unitsSold4[4] + unitsSold5[4]
    let rVal6 = unitsSold1[5] + unitsSold2[5] + unitsSold3[5] + unitsSold4[5] + unitsSold5[5]
    let rVal7 = unitsSold1[6] + unitsSold2[6] + unitsSold3[6] + unitsSold4[6] + unitsSold5[6]

    print("rVal1::\(rVal1)")
    print("rVal2::\(rVal2)")
    print("rVal3::\(rVal3)")
    print("rVal4::\(rVal4)")
    print("rVal5::\(rVal5)")
    print("rVal6::\(rVal6)")
    print("rVal7::\(rVal7)")

    let unitsSold6 = [rVal1,rVal2,rVal3,rVal4,rVal5,rVal6,rVal7,rVal1,rVal2,rVal3,rVal4,rVal5,rVal6,rVal7,rVal1,rVal2,rVal3,rVal4,rVal5,rVal6,rVal7,rVal1,rVal2,rVal3,rVal4,rVal5,rVal6,rVal7,rVal1,rVal2]

    setLineChartData(days, values: unitsSold6)

    slider.minimumValue = 1
    slider.maximumValue = 30

}

func setLineChartData(dataPoints: [String], values: [Double]) {

    var dataEntries: [ChartDataEntry] = []

    for i in 0..<dataPoints.count {

        let dataEntry = ChartDataEntry(value: values[i], xIndex: i)
        dataEntries.append(dataEntry)
    }

    let lineChartDataSet = LineChartDataSet(yVals: dataEntries, label: "Total Sales")
    lineChartDataSet.setColor(UIColor.greenColor().colorWithAlphaComponent(0.5))
    lineChartDataSet.setCircleColor(UIColor.greenColor())
    lineChartDataSet.lineWidth = 2.0
    lineChartDataSet.circleRadius = 2.5
    lineChartDataSet.fillAlpha = 65 / 255.0        
    let lineChartData = LineChartData(xVals: dataPoints, dataSet: lineChartDataSet)
    lineChartView.data = lineChartData 
    lineChartView.rightAxis.enabled = false
    lineChartView.xAxis.enabled = false
    lineChartView.descriptionText = ""
    lineChartView.drawMarkers = true

}


@IBAction func sliderValueChanged(sender: UISlider) {

    let currentValue = Int(sender.value)
    lblSlider.text = "Day \(currentValue)"
    print("slidervalue::\(lblSlider.text)")
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func chartValueSelected(chartView: ChartViewBase, entry: ChartDataEntry, dataSetIndex: Int, highlight: ChartHighlight) {
    print("ChartValueSelected")  
}

}

Error:-fatal error: drawHighlighted() cannot be called on ChartDataRendererBase: file /Users/MyMac/Documents/MyChart-Demo/Pods/Charts/Charts/Classes/Renderers/ChartDataRendererBase.swift, line 48

@liuxuan30
Copy link
Member

don't you see drawHighlighted() cannot be called on ChartDataRendererBase?

@Prathame5h
Copy link
Author

Prathame5h commented Jul 4, 2016

when i am touching at any filled circle it is going to crash and gives following error
Error:-fatal error: drawHighlighted() cannot be called on ChartDataRendererBase: file /Users/MyMac/Documents/MyChart-Demo/Pods/Charts/Charts/Classes/Renderers/ChartDataRendererBase.swift, line 48

screen shot 2016-07-04 at 10 47 09 am

so please help me to solved out this...

@liuxuan30
Copy link
Member

liuxuan30 commented Jul 4, 2016

well.. this is not the right place to ask such question, it's more like a programming issue, and stack overflow is the right place.

to your question, you have to check the back trace why the chart object is base class, e.g. not LineChartRenderer but ChartRendererBase

@liuxuan30
Copy link
Member

or could you reproduce it with ChartsDemo

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

2 participants