简体   繁体   中英

why my highchart code is not working?

I have this in my drilldown event of highcharts which works right.

if (!e.seriesOptions) {
    var s=e.point.name;
    var chart = this,
        drilldowns = {
         'SAR': {
                name: 'SAR',
                data: yearData,
            }

        },
        series = drilldowns[e.point.name];

    chart.addSeriesAsDrilldown(e.point, series);                                       
}

but when I replace string 'SAR' with e.point.name

if (!e.seriesOptions) {
    var s=e.point.name;
    var chart = this,
        drilldowns = {
         s: {
                name: s,
                data: yearData,
            }

        },
        series = drilldowns[e.point.name];

    chart.addSeriesAsDrilldown(e.point, series);
}

it does not show any drilldown data where in e.point.name has got string 'SAR' in it.

You cannot create a JS-Object like you intent to do:

var s = 'SAR',
drilldowns = {
  s: {
    name: s,
    data: [],
  }
}

will create an object drilldown with the key s instead of SAR :

{s: {name: "SAR", data: [] }}

You can however use a String for a key with bracket notation:

var s = 'SAR', 
drilldowns = {};

drilldowns[s] = { 
  name: s, 
  data: []
}

will create an drilldown-object with the right keys for you:

{SAR: {name: "SAR", data: []}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM