Components Interactions Examples Tutorials API FAQ

Click

A Click interaction allows the user to trigger an event when a Component is clicked. For example, it can be used to select a bar in a Plots.Bar.

var xScale = new Plottable.Scales.Linear();
var yScale = new Plottable.Scales.Linear();

var data = [];
for (var i = 1; i < 10; i++) { data.push({"x": i, "y": i}); }

var plot = new Plottable.Plots.Bar()
  .x(function(d) { return d.x; }, xScale)
  .y(function(d) { return d.y; }, yScale)
  .addDataset(new Plottable.Dataset(data));

var interaction = new Plottable.Interactions.Click();
interaction.onClick(function(point) {
  plot.selections().attr("fill", "#5279c7");
  var selection = plot.entitiesAt(point)[0].selection;
  selection.attr("fill", "#F99D42");
});
interaction.attachTo(plot);

plot.renderTo("svg#example");

Public Methods