Chartwrapper with dataTable class features, formatted label/value

280 views
Skip to first unread message

Ben

unread,
Aug 31, 2011, 2:43:18 PM8/31/11
to Google Visualization API
Hi,

Is there a way to use chartwrapper without declaring a datatable
object to use the formated text view?

say i want this as the data table:
var data = [['name','rate1','rate2'],
['Shoes', {v:.12, f:'12.0%'}, {v:.12, f:'12.0%'}],
['Toys', {v:0, f:'0%'},{v:.12, f:'12.0%'}],
['Electronics', {v:.21, f:'21%'},{v:.12, f:'12.0%'}],
['Food', {v:.22, f:'22%'},{v:.12, f:'12.0%'}]
];

var wrapper = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
dataTable: data,
options: {title: 'Test'},
containerId: 'visualization'
});

wrapper.draw();

This is not working working because it is throwing an error for the
{v...f} object.

As a workaround i need to create a DataTable:

var data = new google.visualization.DataTable();
data.addColumn('string', 'Month');
data.addColumn('number', 'Rate');
data.addColumn('number', 'Rat3');

data.addRows([
['Shoes', {v:.12, f:'12.0%'}, {v:.12, f:'12.0%'}],
['Toys', {v:0, f:'0%'},{v:.12, f:'12.0%'}],
['Electronics', {v:.21, f:'21%'},{v:.12, f:'12.0%'}],
['Food', {v:.22, f:'22%'},{v:.12, f:'12.0%'}]
]);

Is it possible to avoid this in the ChartWrapper class?

thanks

asgallant

unread,
Aug 31, 2011, 2:53:41 PM8/31/11
to google-visua...@googlegroups.com
Constructing your dataTable object literally (http://code.google.com/apis/chart/interactive/docs/reference.html#dataparam), instead of using the #arrayToDataTable method (used implicitly when you pass an array instead of an object) should work.

sahana tambi

unread,
May 1, 2013, 7:33:21 PM5/1/13
to google-visua...@googlegroups.com
function init() {
  var data = new google.visualization.DataTable(<?php echo $jsonTable; ?>);
  
  wrapper = new google.visualization.ChartWrapper({
    dataTable: data,
    containerId: 'visualization',
    chartType: 'LineChart'
  });
  wrapper.draw();
}

This code does not work, it says tabke has no columns; but when I do a work around and do the following it works:
function init() {
  var data = {"cols":[{"label":"Weekly Task","type":"string"},{"label":"Percentage","type":"number"}],"rows":[{"c":[{"v":"Sleep"},{"v":30}]},{"c":[{"v":"Watching Movie"},{"v":10}]},{"c":[{"v":"Job"},{"v":40}]},{"c":[{"v":"Exercise"},{"v":20}]},{"c":[{"v":"Cooking"},{"v":10}]}]};

  wrapper = new google.visualization.ChartWrapper({
    dataTable: data,
    containerId: 'visualization',
    chartType: 'LineChart'
  });
  wrapper.draw();
}

When I try to echo <?php echo $jsonTable; ?>, my php returns a correct a JSON table; How do I get it working?

asgallant

unread,
May 2, 2013, 12:47:34 AM5/2/13
to google-visua...@googlegroups.com, sahana...@gmail.com
If the JSON was correct, then this would work, hence the JSON is not correct.  Can you post a sample of the JSON output?
Reply all
Reply to author
Forward
0 new messages