Skip to content

Bug: Improve handling of lines with no points #1487

@orwant

Description

@orwant
What steps will reproduce the problem? Please provide a link to a
demonstration page if at all possible, or attach code.

https://code.google.com/apis/ajax/playground/?type=visualization#line_chart

In the LineChart Code Playground, the following code results in an 'Data column(s)
for axis #0 cannot be of type string' error being displayed:

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
        ['Date','line1', 'line2'],
        [new Date(2014, 01, 18), null, null],
        [new Date(2014, 01, 19), null, null],
        [new Date(2014, 01, 20), null, null],
        [new Date(2014, 01, 21), null, null],
  ]);

  // Create and draw the visualization.
  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data);
}

Also, the following code results in an 'All series on a given axis must be of the same
data type' error being displayed.

function drawVisualization() {
  // Create and populate the data table.
  var data = google.visualization.arrayToDataTable([
        ['Date','line1', 'line2'],
        [new Date(2014, 01, 18), null, 1],
        [new Date(2014, 01, 19), null, null],
        [new Date(2014, 01, 20), null, null],
        [new Date(2014, 01, 21), null, null],
  ]);

  // Create and draw the visualization.
  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data);
}

It appears that both errors occur because the type of a line with all null entry points
can't be determined.  The following resolves both issues (although the x axis created
in either case isn't the most ideal):

function drawVisualization() {
  // Create and populate the data table.
        var data = new google.visualization.DataTable();
        data.addColumn('date', 'Date');
        data.addColumn('number', 'line1');
        data.addColumn('number', 'line2');
        data.addRows([
            [new Date(2014, 01, 18), null, null],
            [new Date(2014, 01, 19), null, null],
            [new Date(2014, 01, 20), null, null],
            [new Date(2014, 01, 21), null, null],
        ]);

  // Create and draw the visualization.
  new google.visualization.LineChart(document.getElementById('visualization')).
      draw(data);
}

It'd be best to just not print any points for lines that have all null values instead
of printing the error messages.  Or, maybe it'd be better to just have error messages
that better explain what's going on in these cases?  It took me a while to actually
identify what was causing the problems, since just having null values mixed in works
with no problems.

I know these are probably weird cases, but I'm using the visualization API with dynamically
generated data and have hit both of these before.

Anyway, thanks for looking into this, and thanks for writing such a useful API!

What component is this issue related to (PieChart, LineChart, DataTable,
Query, etc)?

LineChart

Are you using the test environment (version 1.1)?
(If you are not sure, answer NO)
NO

What operating system and browser are you using?
Windows/Linux Firefox

*********************************************************
For developers viewing this issue: please click the 'star' icon to be
notified of future changes, and to let us know how many of you are
interested in seeing it resolved.
*********************************************************

Original issue reported on code.google.com by hockeyplayer363 on 2014-02-17 21:48:56

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions