I'm using google scatterchart to show where defects are on a surface. All defects have an ID, when I click on a point I want an event to fire from where I can get that ID and do other stuff with it.
In google chart one can wire an selecthandler from where I can get what's selected, but how do I add an ID (or any other data) in the dataTable to a point without it being displayed?
For example:
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('number', 'Width');
dataTable.addColumn('number', 'Yellow');
dataTable.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true } });
dataTable.addColumn('number', 'Red');
dataTable.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true } });
dataTable.addColumn('number', 'Id'); <-- this doesn't work
The last column I want to add the ID of the defect and retrieve it via the selectHandler.
dataTable.addRow([123, 123, 'some tooltip', null, null, 999]);
Here I added ID 999 to the table. But I don't want the chart to display it. How do I add additional (hidden) data to a point?
setRowProperties(rowIndex, properties)
would work in this case, remove Id column and add dataTable.setRowProperties(0,{'id':'999'});
You can get the property of the row by using getRowProperties(rowIndex);
You can add extra columns containing any information you want, and then hide them with a DataView:
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('number', 'Width');
dataTable.addColumn('number', 'Yellow');
dataTable.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true } });
dataTable.addColumn('number', 'Red');
dataTable.addColumn({ type: 'string', role: 'tooltip', 'p': { 'html': true } });
dataTable.addColumn('number', 'Id');
// populate dataTable
var view = new google.visualization.DataView(dataTable);
// exclude column 5 (Id)
view.setColumns([0, 1, 2, 3, 4]);
Then draw your chart using the DataView instead of the DataTable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With