Sam Fisher
Sam Fisher

Reputation: 848

How to get bar id in react highcharts?

I form charts and a have such series format:

series: {
                            id  : '001',
                            name: 'name,
                            data: [],
                            color: '#fff'
                        }

In plotOptions I created onClick event:

plotOptions: {
                series: {
                    stacking: 'normal',
                    cursor: 'pointer',
                    allowPointSelect: true,
                    marker: {
                        states: {
                            select: {
                                enabled: true
                            }
                        }
                    },
                    point: {
                        events: {
                            click: function () {
                                console.log('!!!!!', this);
                            }
                        }
                    }
                }
            }

After clock i get object in log. There is all information except id: '001'. How can I get it?

Upvotes: 0

Views: 358

Answers (1)

morganfree
morganfree

Reputation: 12472

You attached the click event to the point, so this inside the callback refer to the point object. Id is defined in series' options.

You can access it from series.options object:

point: {
  events: {
    click: function() {
      console.log('!!!!!', this.series.options.id);
    }
  }
}

live example: http://jsfiddle.net/4s3ayhfy/

Upvotes: 2

Related Questions