我有一个highcharts脚本,用于计算图表中的平均值并绘制一条显示平均线的线。 我想在用户点击鼠标时绘制线条,但不知道在哪里放置代码。
beforeDrawSeries: function(series, seriesOptions, tempChart, seriesIndex)
{
var totalValue = 0;
// First, find the average value for the series
for ( var i = 0; i < series.data.length; i++ )
{
totalValue += series.data[i].y;
}
aveValue = totalValue / series.data.length;
for ( var j = 0; j < series.data.length; j++ )
{
// Find out if this data point is above average
if ( series.data[j].y <= aveValue )
{
continue;
}
//een muisklik
//return;
//object.onclick=function();
//continue;
// The data point is above average. Color it green
//var pointOptions = seriesOptions.data[j];
//pointOptions.color = 'green';
}
},
afterRendering: function(myChart)
{
var chart=myChart.getCore();
var mySeries = chart.series[0];
// Assuming aveValue was set in the beforeDrawSeries function,
// draw a plot line at the average value.
mySeries.yAxis.addPlotLine({
color: 'orange',
width: 2,
value: aveValue,
id: 'averageValuePlotLine',
zIndex: 2
});
}