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

Legend colors not correct #617

Closed
andheiberg opened this issue Dec 18, 2015 · 2 comments
Closed

Legend colors not correct #617

andheiberg opened this issue Dec 18, 2015 · 2 comments

Comments

@andheiberg
Copy link

This is obviously a problem with my setup. Using the same code in the iOSChartsDemo project works as you would expect. But in my project it results in the bars being red and the legend being turquoise.

Image of resulting chart

Really sorry waisting peoples time with this issue, but I don't see an obvious fix.

        heightChart.noDataText = "You need to provide data for the chart."
        heightChart.descriptionText = ""

        var dataEntries: [BarChartDataEntry] = []

        for i in 0..<dataPoints.count {
            let dataEntry = BarChartDataEntry(value: values[i], xIndex: i)
            dataEntries.append(dataEntry)
        }

        let chartDataSet = BarChartDataSet(yVals: dataEntries, label: "Units Sold")
        let chartData = BarChartData(xVals: months, dataSet: chartDataSet)
        heightChart.data = chartData

        chartDataSet.colors = [UIColor(red: 230/255, green: 0/255, blue: 0/255, alpha: 1)]

        heightChart.xAxis.labelPosition = .Bottom

        heightChart.backgroundColor = UIColor.clearColor()

        heightChart.animate(xAxisDuration: 2.0, yAxisDuration: 2.0, easingOption: .EaseInBounce)
@andheiberg
Copy link
Author

My temporary fix is

heightChart.legend.setCustom(colors: [UIColor(red: 230/255, green: 0/255, blue: 0/255, alpha: 1)], labels: ["Units Sold"])

@liuxuan30
Copy link
Member

I guess you need to put heightChart.data = chartData at the last line. or call notifyDataSetChanged

It's a limitation that you have to first configure chart view's property, and then setup the data set, and the call heightChart.data = chartData. Otherwise some calculation will be wrong. Or you remember to call notifyDataSetChanged.

computeLegend is called in notifyDataSetChanged, and notifyDataSetChanged is called once you call chart data setter. notifyDataSetChanged is a very important func, if you changed anything that needs to be recalculated.

Take a look at notifyDataSetChanged and related functions will help you avoid some strange issue :)

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