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

the BubbleChartDataSet colors property is bound to chart view x-axis, not data-set entries (Charts 3.0.2) #2839

Open
ernest-bruce opened this issue Oct 1, 2017 · 1 comment

Comments

@ernest-bruce
Copy link

ernest-bruce commented Oct 1, 2017

while working with bubble data sets and charts i noticed that in bubble data sets, even though the documentation for ChartBaseDataSet.colors says that colors are bound to data-set entries, when you assign colors to the data set and render it in a bubble chart view, Charts 3.0.2 bounds the data-set colors to the x-axis range, not the data-set entries. line 95 in BubbleChartRenderer.swift confirms this:
for j in stride(from: _xBounds.min, through: _xBounds.range + _xBounds.min, by: 1)

that’s different from a similar line (299) in BarChartRenderer.swift:
for j in stride(from: 0, to: buffer.rects.count, by: 1)

i had a hard time understanding why my color assignments weren’t being followed in bubble charts. the documentation for the BubbleChartDataSet and BubbleChartRenderer classes don’t mention this diversion from the guidance provided in ChartBaseDataSet.swift for the colors property.

however, because i have to “expand” my colors array to include slots for all the items in the x-axis to have the colors correctly assigned to the data entries on the chart, i wonder whether the issue is in the documentation or the implementation.

attached are my supporting materials.

bubble_color_mismatch

bubble_color_ok

[iOSChartsDemo.zip](https://github.com/danielgindi/Charts/files/1347357/iOSChartsDemo.zip)
@liuxuan30
Copy link
Member

liuxuan30 commented Oct 13, 2017

I'm trying to understand your question, but I don't understand your image. Are you asking you want to use entry index in the data set, instead of the x?

current bubble chart uses let color = dataSet.color(atIndex: Int(entry.x)) to determine the color. However, using the entry index seems equivalent to using entry.x here, because basically Int(entry.x) = j in bubble chart (unless you have specified user case where x is decimal rather than int).

for j in stride(from: _xBounds.min, through: _xBounds.range + _xBounds.min, by: 1)
{
     guard let entry = dataSet.entryForIndex(j) as? BubbleChartDataEntry else { continue }

what I debugged and print out j and Int(entry.x) is the same here.

if your x is decimal here and x=2.1, x=2.2 are two different x grid lines for you, Int(2.1) and Int(2.2) will lead to the same color while you want them two different color?

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