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

LineChartData omits and misaligns values when data isn't continuous #728

Closed
UberJason opened this issue Feb 1, 2016 · 3 comments
Closed

Comments

@UberJason
Copy link

Hi,

I'm not sure if this is a bug or intended behavior, but it wasn't intuitive for me at least. Suppose you have the following array of eight ChartDataEntries, which is just entries from 0 to 9 but missing values for xIndex = 3 and 6:

let dataSet = [
ChartDataEntry(value: 0, xIndex: 0),
ChartDataEntry(value: 1, xIndex: 1),
ChartDataEntry(value: 2, xIndex: 2),
ChartDataEntry(value: 4, xIndex: 4),
ChartDataEntry(value: 5, xIndex: 5),
ChartDataEntry(value: 7, xIndex: 7),
ChartDataEntry(value: 8, xIndex: 8),
ChartDataEntry(value: 9, xIndex: 9),
]

The data is missing values for xIndex = 3 and 6. If my xVals array matches that set of ChartDataEntries exactly:

let xVals = ["0", "1", "2", "4", "5", "7", "8", "9"]
let data = LineChartData(xVals: xVals, dataSet: dataSet)
chartView.data = data

Then the chart comes out showing only six values which are misaligned:

bad

On the other hand, if my xVals array purposely includes the missing two xIndex values:

let xVals = ["0", "1", "2", "3", 4", "5", "6", "7", "8", "9"]
let data = LineChartData(xVals: xVals, dataSet: dataSet)
chartView.data = data

Then the chart comes out the way I expect it to, with eight values properly aligned:

good

My question is, is this a bug or intended functionality? I would expect these two graphs to match. In the first case, I would expect that the graph would be able to interpolate the gaps between the labels (and just leave them blank, if necessary). Even though the xVals array of labels alone doesn't inform where the gaps should go, the data set shows where the gaps are.

@UberJason UberJason changed the title LineChartData misaligns values when data isn't continuous LineChartData omits and misaligns values when data isn't continuous Feb 1, 2016
@liuxuan30
Copy link
Member

This is intended. If you don't want a value at specific xIndex, simply add xIndex without any data entry for it.

@UberJason
Copy link
Author

Is this documented somewhere that I've missed it? Personally I find that very unintuitive. Why is it designed this way? Now when you have a data set with missing data, you have to go through and find and manually include the intermediate x-values for that missing data.

@liuxuan30
Copy link
Member

In old issues, while talking about nil value. I think it's not intuitive, but designing like this would have less issues. The idea is, the distance between 2 index on x axis is equal, based on index. Because the line chart does not know how you want to ignore it. Using index is straightforward.

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