Adding additional data to Series.Data

Oct 21, 2013 at 3:19 PM
Hi,

I'd like to create a bar chart that allows you to click on each bar and be taken to a different URL. I've found a nice example of this here.

The most interesting part of this example is that a 'url' is added to each element of the data array.
series: [{
            data: [{
                y: 29.9,
                url: 'http://bing.com/search?q=foo'
            }, {
                y: 71.5,
                url: 'http://bing.com/search?q=bar'
            }, {
                y: 106.4,
                url: 'http://bing.com/search?q=foo+bar'
            }]        
        }]
Is it possible to create an array like this using DotNet.Highcharts? Looking at the Data object it seems that I can't add this additional data to the array, is there a way?

Any suggestion would be welcome.
Thanks.
Coordinator
Oct 24, 2013 at 12:13 PM
Hi,

Your data should looks like this:
object[] data = new object[]
                {
                    new { y = 29.9, url = "http://bing.com/search?q=foo" },
                    new { y = 71.5, url = "http://bing.com/search?q=bar" },
                    new { y = 106.4, url = "http://bing.com/search?q=foo+bar" }

                };
and the Highcharts object:
Highcharts chart = new Highcharts("chart")
                .InitChart(new Chart { Type = ChartTypes.Column })
                .SetXAxis(new XAxis
                {
                    Categories = new[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }
                })
                .SetPlotOptions(new PlotOptions
                    {
                        Series = new PlotOptionsSeries
                            {
                                Cursor = Cursors.Pointer,
                                Point = new PlotOptionsSeriesPoint
                                    {
                                        Events = new PlotOptionsSeriesPointEvents
                                            {
                                                Click = "function() { location.href = this.options.url; }"
                                            }
                                    }
                            }
                    })
                .SetSeries(new Series { Data = new Data(data) });
Regards,
Vangi
Marked as answer by Vangi on 10/24/2013 at 5:24 AM
Oct 24, 2013 at 12:23 PM
Wow, that simple. Excellent, thank you very much for the quick response. I'll give it a try now.