Skip to content

Commas in data cause data to become misinterpreted #161

@ggamir

Description

@ggamir

Hi there,

There's an issue when you have/need a comma in any element in the data you'd like to pass to C3, that data series will be misinterpreted and the display will be incorrect.

The data array is reduced to a string with comma-separated elements when it's passed to the angular directive, and later there is logic to useString.split(',') to recreate the array for use in the C3 config object.

Example:
Notice the original data set begins with 2 elements and ends up with 4.
["a, b", "x, y"] -> "a, b,x, y".split(',') -> ["a", " b", "x", " y"]

Does anyone have any ideas on how to resolve this? Using an html entity number to represent the comma doesn't work because at the bottom of the stack, C3 or D3 is escaping html characters.

I thought about having an escape character or something before the comma or around the comma, and instead of doing String.split(','), we could do ["a%,% b,x%,% y"].split(/(?!%),(?!%)/) and then we'd have to .map(d => d.replace('%,%', ',')) to make it appear as intended.

http://stackoverflow.com/questions/42691215/how-to-make-c3-ignore-comma-in-column-values/42777308?noredirect=1#comment72733784_42777308

Area in code that this specific instance is happening: https://github.com/jettro/c3-angular-directive/blob/master/src/column-directive.js#L48

But there are other places where /\.split\(['"],["']\)/ is being used

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions