Skip to content

chart.getCSV() doesn't add empty cells at the end of the row #17186

@mik-the-deutsch-dev

Description

@mik-the-deutsch-dev

chart.getCSV() doesn't add empty cells at the end of the row. Although according to the CSV specification "Within the header and each record, there may be one or more fields, separated by commas. Each line should contain the same number of fields throughout the file." Taken from rfc4180. So there should be the same number of delimiters in every row.

Most CSV parsers do still open the CSV like this. But this thing causes some trouble for the simple solutions, e.g. when you do not want to explicitly ask the user about the delimiter used, but to detect it automatically. If you cannot expect that a CSV has the same number of columns within every row, this adds more errors.

Imagine we have 2 series of points:

A = [ [1, 0.1], [2, 0.2], [3,0.3] ]
B = [ [2, 0.5], [4, 1.0] ]  

Expected behavior (expected CSV output)

  • all rows have equal number of cells

    x,A,B
    1,0.1,
    2,0.2,0.5
    3,0.3,
    4,,1.0
    

Actual behavior

  • rows with x=1 and x=3 have 2 cells, other rows have 3 cells

    x,A,B
    1,0.1
    2,0.2,0.5
    3,0.3
    4,,1.0
    

Live demo with steps to reproduce

Product version

Highcharts 10.0.0 (latest)

Affected browser(s)

  • all, but it is not a browser-dependent issue

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions