我有以下代码
var onload = function () {
var mainData = [data1];
var cList=[];
for (var i = 0; i < mainData[0].cars.length; i++) {
var obj = mainData[0].cars[i];
var chlst = obj.name; //THIS ONE GETS THE NAME VALUE ... I ALSO WANT THE ID
cList.push(chlst);
}
jQuery('#container').highcharts({
chart: {
type: 'column'
},
title: {
text: ''
},
xAxis: {
categories: cList,
labels: {
rotation: -45,
style: {
fontSize: '10px'
}
}
},
yAxis: {
min: 0,
title: {
enabled: true,
text: '',
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
}
}
},
legend: {
align: 'right',
x: -30,
verticalAlign: 'top',
y: 25,
floating: true,
backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white',
borderColor: '#ccc',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function () {
return '<b>' + this.x + '</b><br/>' +
this.series.name + ': ' + this.y;
}
},
plotOptions: {
series: {
cursor: 'pointer',
point: {
events: {
click: function () {
alert(this.category);
},
},
},
},
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
style: {
textShadow: '0 0 3px black'
}
}
}
},
series: [{
name: 'other',
data: o1 //ignore this part
}, {
name: 'other2',
data: o2 //ignore this part
}]
});
在Click事件中,当我添加它时:
alert(this.category); //Returns the Name ...But I also need the Id
它会给我cList中点击栏的值,这很好但是这给了我名字值(这是旧的添加到cLIst),但我还需要获取id而不显示它在图表中。
我该怎么做?