Click here to Skip to main content
15,888,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi, I created a chart using highcharts in birt developer pro.
there is a script that computes the average and shows that avg as a line.
I would like that script to run when the user clicks on the chart, so I thought adding a simple event handler at the beginning of the script would do the trick. but so far i haven't gotten it to work.
here's the script (I commented out the bit at the beginning that doesn't work)
anyone know what I should do?

JavaScript
//object.addEventListener("click", myScript);

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;
}

// 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
});

// Add a legend item that labels the plot line
// Do this by adding an empty series
chart.addSeries({
name: 'Gemiddeld: ' + aveValue.toFixed(2),
color: 'orange',
marker: {
enabled: false
}
});
},
Posted
Updated 12-Jul-15 22:57pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900