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

Scatter chart data set color not working #784

Closed
jpv123 opened this issue Mar 2, 2016 · 3 comments
Closed

Scatter chart data set color not working #784

jpv123 opened this issue Mar 2, 2016 · 3 comments

Comments

@jpv123
Copy link

jpv123 commented Mar 2, 2016

Hello. I have a scatter chart view that works correctly. It has many data sets and the values are displaying normally. To each data set I'm assigning different colors like this

if mainIndex == 0 {
    indexDataSet.setColor(UIColor.redColor())
} else if mainIndex == 1 {
    indexDataSet.setColor(UIColor.blueColor())
} else if mainIndex == 2 {
    indexDataSet.setColor(UIColor.greenColor())
} else {
    indexDataSet.setColor(UIColor.yellowColor())
}

However when I run the code, all the values are yellow. It seems that the chart takes only the color of the last data set. Any ideas on how to solve this?

Thanks

@liuxuan30
Copy link
Member

ChartsDemo's scatter chart could have different colors. Please look at
- (void)setDataCount:(int)count range:(double)range in scatter chart view controller for how to set the colors.

if it's always yellow, I suspect either indexDataSet is the same or mainIndex has problems

@jpv123
Copy link
Author

jpv123 commented Mar 2, 2016

Can you please take a look at the code? maybe i'm missing something

var indexDataEntriesArray = [ChartDataEntry]()
var indexDataSetArray = [ScatterChartDataSet]()

var index = 0
var mainIndex = 0
for mainObject in mainArray {
    for value in mainObject.valuesArray {
        let scatterDataEntry = ChartDataEntry(value:value, xIndex: index)
        indexDataEntriesArray.append(scatterDataEntry)

        index++
    }

    let indexDataSet = ScatterChartDataSet(yVals: indexDataEntriesArray, label: "")
    if mainIndex == 0 {
        indexDataSet.setColor(UIColor.redColor())
    } else if mainIndex == 1 {
         indexDataSet.setColor(UIColor.blueColor())
    } else if mainIndex == 2 {
         indexDataSet.setColor(UIColor.greenColor())
    } else {
         indexDataSet.setColor(UIColor.yellowColor())
    }
    indexDataSet.label = ""
    indexDataSet.drawHorizontalHighlightIndicatorEnabled = false
    indexDataSet.drawVerticalHighlightIndicatorEnabled = false
    indexDataSet.scatterShape = .Circle
    indexDataSet.scatterShapeSize = 5
    indexDataSetArray.append(indexDataSet)

    mainIndex++
    index = 0
}

//Add all datasets
let indexData = ScatterChartData(xVals: yearsArray)
for indexDataSet in indexDataSetArray {
    indexData.addDataSet(indexDataSet)
}

indexChartView.data = indexData
indexChartView.setNeedsDisplay()

@liuxuan30
Copy link
Member

well with a glimpse, it seems fine, but you need to debug it on your own, it's more efficient, especially you have ChartsDemo to play with.

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