views:

167

answers:

3

Hey all !

I am building a line chart and I would like, when I click on a point of the line, to display a popup containing some data about this point. The issue I try to resolve is to get the id, the series associated with this point or something like that.

Here is my code :

plotOptions: {
      column: {
        pointWidth: 20
      },

      series: {
        cursor: 'pointer',
        events: {
          click: function(event) {
            requestData(event.point);
          }
        }
      }

I tried

requestData(this.point)

,

requestData(this.point.id)

also but it doesn't work.

How do we get the id of a point ?

Thanks a lot.

A: 

Use the HighCharts API.

You can look more into the Point Object Methods.

Frankie
Yes I've already done it... Basically how to get this point ?When I put this.point, it says undefined, is it normal ?
Johann
+1  A: 

According to the docs, event.point holds a pointer to the nearest point on the graph.

So I'd write the event.point to the console, and see what's available.

console.log(event.point);

From the docs:

click: Fires when the series is clicked. The this keyword refers to the series object itself. One parameter, event, is passed to the function. This contains common event information based on jQuery or MooTools depending on which library is used as the base for Highcharts. Additionally, event.point holds a pointer to the nearest point on the graph.

Example based on the example from the docs: http://jsfiddle.net/5nTYd/

Click a point, and check the console.

patrick dw
When I try event.point.id, I have undefined too..
Johann
@Johann - I updated my answer. Log `event.point` to the console to see what properties are available to you from the nearest `point` that was clicked.
patrick dw
Here is what I obtain in my console :Processing ChartsController#return_data (for 127.0.0.1 at 2010-08-19 13:10:36) [GET] Parameters: {"name"=>"[object Object]", "_"=>"1282248635940"}
Johann
event.point is just an [object Object] and it doesn't say what properties are available...
Johann
What browser are you using? You should be able to expand the `Object` to see all its properties. In Safari/Chrome or Firebug dev tools, you click the `Object` in the console. If you're using IE8, I'm not sure. If you're doing an `alert()` then you'll just get `[object Object]`. If that's the case, I'd recommend using developer tools instead.
patrick dw
A: 

I tried to do this and published a very small blog. Hope this helps if you still havent found the solution. http://www.spritle.com/blogs/?p=859

alokswain