google / google-visualization-issues

288 stars 35 forks source link

Bug: data.join() forces annotations to read from formatted string values #1235

Open orwant opened 9 years ago

orwant commented 9 years ago
What steps will reproduce the problem? Please provide a link to a
demonstration page if at all possible, or attach code.
1. Compile the following code with container div with id 'visualization' (I used the
LineChart playground page, although it appeared elsewhere first):
#############CODE##############
function drawVisualization() {
  // Create and populate the data table.
  var data = new google.visualization.DataTable();
  data.addColumn('string', 'x');
  data.addColumn({name: 'notes', type: 'string', role:'annotation'});
  data.addColumn('number', 'Cats');
  data.addColumn('number', 'Blanket 1');
  data.addRows([
    ['A','test',   1,           undefined],
    ['B','', undefined, undefined],
    ['C','',   2,         undefined],
      ['D','',   1,          undefined]
  ]);

  var data1 = new google.visualization.DataTable();
  data1.addColumn('string', 'x');
  data1.addColumn('number', 'Blanket 1');
  data1.addRows([
    ['A', .5],
    ['B', undefined],
    ['C', 1],
    ['D', .5]
  ]);

  //log all of the annotation column cells
  console.log("original " + (JSON.stringify(JSON.parse(data.toJSON())["rows"].map(function(x){return
x["c"][1];}))));
  console.log("");
  data = google.visualization.data.join(data, data1, "full", [[0, 0]], [1,2], [1]);

  var chart = new google.visualization.ChartWrapper({
    'chartType': 'LineChart',
    'dataTable': data,
    'containerId': 'visualization',
    'options': {
      'interpolateNulls': true,
      'annotation': {
        1: {style: 'line'}//to make the annotations obvious
      }
    }
  });

  var wantItToWork = false;
  data.setValue(1,1,'test2');
  if(wantItToWork)
    data.setFormattedValue(1,1,'test2');
  //log all of the annotation column cells
  console.log("new " + (JSON.stringify(JSON.parse(data.toJSON())["rows"].map(function(x){return
x["c"][1];}))));
  chart.draw();
##################################################
2. The second annotation is displayed as 'undefined', despite having a string value
in the table (also, join creates a formatted value for the first annotation).
3. Set wantItToWork to true to add a format string, the annotation now displays correctly.
4. Comment out the join statement, now the second annotation displays correctly regardless
of whether a formatted value is added.

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

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 7, Chrome 27.0.1453.110 m, Firefox 21.0

*********************************************************
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 kyle.l.wiley on 2013-06-14 18:01:48

orwant commented 9 years ago
Made a mistake while copying the code, it needs a } on the very end to close the function.

Original issue reported on code.google.com by kyle.l.wiley on 2013-06-14 18:03:29