How do I access series.data anywhere in .highcharts() function?

maximumride

I plan to put the data in y-axis in a mouseover event of my x-axis labels, so that when a user hovers on an x-axis label, it will display a summary text of the values in my stack chart.

Question is how do I access y-axis data inside my x-axis:{...} code

here's my code http://jsfiddle.net/BkxhA/3/

       $(function () {

        var categoryImgs = {
            'AIA': '<img src="http://dummyimage.com/60x60/ff6600/ffffff"><img>&nbsp;',
            'AMP':'<img src="http://highcharts.com/demo/gfx/sun.png"><img>&nbsp;',
            'AMP RPP':'<img src="http://highcharts.com/demo/gfx/sun.png"><img>&nbsp;',
            'Asteron Life':'<img src="http://highcharts.com/demo/gfx/sun.png"><img>&nbsp;',
            'Fidelity Life':'<img src="http://highcharts.com/demo/gfx/sun.png"><img>&nbsp;'
        };

        var totals = new Array();
        var stackTotals = new Array();
        var i = 5, j = 0;
        //totals = HighchartsAdapter
        function reverse() {
            totals.reverse();
        }

        $('#container').highcharts({
            chart: {
                type: 'column'
            },

            title: {
                text: 'Premium Summary'
            },
            yAxis: {
                min: 0,
                title: {
                    text: ''
                },
                labels: {
                    formatter: function () {                            
                        return '$' + this.value;
                    }
                },
                stackLabels: {
                    enabled: true,
                    style: {
                        fontWeight: 'bold',
                        color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray',                                                        
                    },                                                
                    formatter: function () {
                        totals[i++] = this.total;                           
                        return '';
                    }, 

                }                    
            },  

            xAxis: {
                categories: ['AIA', 'AMP', 'AMP RPP', 'Asteron Life', 'Fidelity Life'],
                labels: {
                    x: 5,
                    useHTML: true,

                    formatter: function () {                           

                        var n = totals.shift();
                        return '<div class="stacktotal">$' + n +  '</div><div class="myToolTip" title="Hello ' + this.value + '">' + categoryImgs[this.value] + '</div>';

                    },
                    events: {
                        mouseover: function () {
                            $('#hoverboard').html('<img name="testimg" src="http://highcharts.com/demo/gfx/sun.png"><p>This should be the series y-axis data (this.series.data...something)<p>');
                        },
                        mouseout: function () {
                            $('#hoverboard').html('');
                        }                            
                    },
                }                    
            },

            linkedTo: 0,
            categories: ['AIA', 'AMP', 'AMP RPP', 'Asteron Life', 'Fidelity Life'],

            legend: {
                align: 'right',
                x: -70,
                verticalAlign: 'top',
                y: 20,
                floating: true,
                backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColorSolid) || 'white',
                borderColor: '#CCC',
                borderWidth: 1,
                shadow: false
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.x + '</b><br/>' +
                        this.series.name + ': ' + this.y + '<br/>' +
                        'Total: ' + this.point.stackTotal;
                }
            },
            plotOptions: {
                column: {
                    stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white',
                        style: {
                            textShadow: '0 0 3px black, 0 0 3px black'
                        },
                        format: '${y}'
                    }
                }

            },

            series: [{
                name: 'Policy Fee',
                y:'$' + this.value,
                data: [200.12, 290, 45.78, 71, 120]                    
            }, {
                name: 'WOP',
                data: [150, 210.23, 150, 200, 100]
            }, {
                name: 'Income Protection',
                data: [89, 400, 258.13, 212, 152]
            }, {
                name: 'Life Cover',
                data: [150, 210.23, 150, 200, 100]
            } ]

        });           

    });
Paweł Fus

Looks like plugin has limitations - in event callback this is pointed to DOM element, instead of something in Highcharts.

To achieve what you need, you can add some custom attribute for created HTML tag in formatter, with info you need. For example passing index:

                    formatter: function () {              
                        var axis = this.axis,
                            index = axis.categories.indexOf(this.value);

                        var n = totals.shift();
                        return '<div class="stacktotal" data-index="' + index + '">$' + n +  '</div><div class="myToolTip" title="Hello ' + this.value + '">' + categoryImgs[this.value] + '</div>';

                    },

Then you can get that value in events:

                        mouseover: function () {
                            var chart = $("#container").highcharts(),
                                index = $(this).find('.stacktotal').attr("data-index");

                            console.log('Index', index); //index is index of category
                            var point = chart.series[0].data[index];
                            console.log('Point', point); // point for specific category in first series


                            $('#hoverboard').html('<img name="testimg" src="http://highcharts.com/demo/gfx/sun.png"><p>' + point.total + '<p>');
                        },

Demo with all: http://jsfiddle.net/BkxhA/4/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I access my ubuntu server from anywhere in the world?

From Dev

How can i add dynamic data inside flag series in highcharts

From Dev

How to access zoo component data from anywhere

From Dev

How do I make my Batch Code a command I can access anywhere?

From Dev

How do I detect a tap anywhere in the view?

From Dev

How do you add to tooltip, a series in HighCharts?

From Dev

How to get multiple series data in tooltip highcharts?

From Dev

How to plot line chart with series data in highcharts?

From Dev

How to pass json data to highcharts series?

From Dev

Highcharts: How do I set dynamic data to the drilldown pie chart?

From Dev

how do I access a named parameter in a function?

From Dev

How do I access a function of a different object

From Dev

How do I hide a Highcharts series from the chart, but always show it in the tooltip?

From Dev

How do I access the data in a join SQLAlchemy

From Dev

How do i gain access to grouped data?

From Dev

How do I access MongoDB data?

From Dev

How do i access the private data of an object which is passed by reference to operator= function?

From Dev

how do I access function of Data.js from a controller CandidateCtrl.js in angularjs?

From Dev

How do i access the private data of an object which is passed by reference to operator= function?

From Dev

Highcharts multiple data series

From Dev

how do I apply normalize function to pandas string series?

From Dev

How do I persist a series objects to support a logging function?

From Dev

how do I apply normalize function to pandas string series?

From Dev

HighCharts activity gauge populated with series data from a function

From Dev

How can I access a service installed on Kubernetes from anywhere?

From Dev

How do I deal with Pandas Series data type that has NaN?

From Dev

sql how do i convert a time series data to a hoc

From Dev

Basic Python: How do I normalize a data series?

From Dev

How can I access the 'this' field in plotOptions of highcharts

Related Related

  1. 1

    How do I access my ubuntu server from anywhere in the world?

  2. 2

    How can i add dynamic data inside flag series in highcharts

  3. 3

    How to access zoo component data from anywhere

  4. 4

    How do I make my Batch Code a command I can access anywhere?

  5. 5

    How do I detect a tap anywhere in the view?

  6. 6

    How do you add to tooltip, a series in HighCharts?

  7. 7

    How to get multiple series data in tooltip highcharts?

  8. 8

    How to plot line chart with series data in highcharts?

  9. 9

    How to pass json data to highcharts series?

  10. 10

    Highcharts: How do I set dynamic data to the drilldown pie chart?

  11. 11

    how do I access a named parameter in a function?

  12. 12

    How do I access a function of a different object

  13. 13

    How do I hide a Highcharts series from the chart, but always show it in the tooltip?

  14. 14

    How do I access the data in a join SQLAlchemy

  15. 15

    How do i gain access to grouped data?

  16. 16

    How do I access MongoDB data?

  17. 17

    How do i access the private data of an object which is passed by reference to operator= function?

  18. 18

    how do I access function of Data.js from a controller CandidateCtrl.js in angularjs?

  19. 19

    How do i access the private data of an object which is passed by reference to operator= function?

  20. 20

    Highcharts multiple data series

  21. 21

    how do I apply normalize function to pandas string series?

  22. 22

    How do I persist a series objects to support a logging function?

  23. 23

    how do I apply normalize function to pandas string series?

  24. 24

    HighCharts activity gauge populated with series data from a function

  25. 25

    How can I access a service installed on Kubernetes from anywhere?

  26. 26

    How do I deal with Pandas Series data type that has NaN?

  27. 27

    sql how do i convert a time series data to a hoc

  28. 28

    Basic Python: How do I normalize a data series?

  29. 29

    How can I access the 'this' field in plotOptions of highcharts

HotTag

Archive