Removing datapoint in google chart?

when user selected any datapoint in the chart then a popup window must appear ask that “want to remove selected point what” if user click on ‘yes’ it must remove it r if user click on ‘NO’ then it must not remove it
how to proceed this problem using javascript

You would use an event listener that triggers when something in the chart is selected.

google.visualization.events.addListener(chart, 'select', selectHandler);    

You can then check for what was selected, and whether it was valid:

  function selectHandler() {
    var selectedItem = chart.getSelection()[0];
    var name = "";
    if (selectedItem) {
        name = data.getValue(selectedItem.row, 0);
        ...
    }
  }

If it is valid, you can then ask if they really want to remove the appropriate row, and redraw the chart.

      if (window.confirm("Really remove the " + name + " data point?")) {
      	data.removeRow(selectedItem.row);
      	chart.draw(data);
      }

All together it looks like this:

  function selectHandler() {
    var selectedItem = chart.getSelection()[0];
    var name = "";
    if (selectedItem) {
    	name = data.getValue(selectedItem.row, 0);
      if (confirm("Really remove the " + name + " data point?")) {
      	data.removeRow(selectedItem.row);
      	chart.draw(data);
      }
    }
  }

  google.visualization.events.addListener(chart, 'select', selectHandler);

And a working example can be seen at https://jsfiddle.net/06zoh5jc/1/

Thank You very much giving me a logic

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.