循环使用Highcharts中的系列数据来填充工具提示

时间:2018-05-04 07:01:37

标签: javascript jquery loops highcharts

问题

我正在使用Highcharts来创建散点图,我想知道如何循环系列中的数据,以便我可以使用company nameceo name和{{填充工具提示1}}

我正在阅读Highcharts中有关how to set options的文档,但不清楚这是否是我需要采取的正确解决问题的路径(或者只是如何调用包含数据的对象)< / p>

pay ratio
Highcharts.chart('container', {
  chart: {
    type: 'scatter',
    zoomType: 'xy',
  },
  title: {
    text: null
  },
  subtitle: {
    text: null
  },
  xAxis: {
    title: {
      enabled: true,
      text: 'Median employee pay'
    },
    startOnTick: true,
    endOnTick: true,
    showLastLabel: true
  },
  yAxis: {
    title: {
      text: 'CEO pay'
    }
  },
  legend: {
    enabled: false
    // layout: 'vertical',
    // align: 'left',
    // verticalAlign: 'top',
    // x: 100,
    // y: 70,
    // floating: true,
    // backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF',
    // borderWidth: 1
  },
  plotOptions: {
    scatter: {
      marker: {
        radius: 5,
        states: {
          hover: {
            enabled: true,
            lineColor: 'rgb(100,100,100)'
          }
        }
      },
      states: {
        hover: {
          marker: {
            enabled: false
          }
        }
      },
      tooltip: {
        headerFormat: '<b>{series.ceo}</b><br>',
        pointFormat: '${point.x}, ${point.y}'
      }
    }
  },
  series: [{
    name: 'Male',
    color: 'rgba(119, 152, 191, .5)',
    data: [{
        "ceo": "Charles Gordon",
        "company": "Aegion",
        "y": 2633099,
        "x": 83949,
        "pay_ratio": 36,
        "revenue": 1359,
        "num_employees": 6242
      },
      {
        "ceo": "Warner Baxter",
        "company": "Ameren",
        "y": 8080790,
        "x": 122003,
        "pay_ratio": 66,
        "revenue": 6177,
        "num_employees": 8600
      },
      {
        "ceo": "Jeffrey Hollister",
        "company": "American Railcar",
        "y": 1253886,
        "x": 48147,
        "pay_ratio": 26,
        "revenue": 477,
        "num_employees": 1941
      },
      {
        "ceo": "John Eaves",
        "company": "Arch Coial",
        "y": 9790214,
        "x": 96992,
        "pay_ratio": 101,
        "revenue": 2325,
        "num_employees": 3790
      },
      {
        "ceo": "John Stroup",
        "company": "Belden",
        "y": 7012404,
        "x": 52487,
        "pay_ratio": 133.6,
        "revenue": 2389,
        "num_employees": 8800
      },
      {
        "ceo": "Sharon John",
        "company": "Build-A-Bear Workshop",
        "y": 1894435,
        "x": 6198,
        "pay_ratio": 305.7,
        "revenue": 358,
        "num_employees": 4455
      },
      {
        "ceo": "Diane Sullivan",
        "company": "Caleres",
        "y": 7126554,
        "x": 21528,
        "pay_ratio": 331,
        "revenue": 2786,
        "num_employees": 12055
      },
      {
        "ceo": "Eric Brunngraber",
        "company": "Cass Information Systems",
        "y": 2347314,
        "x": 57776,
        "pay_ratio": 40.6,
        "revenue": 137,
        "num_employees": 1081
      },
      {
        "ceo": "Michael Neidorff",
        "company": "Centene",
        "y": 25259468,
        "x": 66600,
        "pay_ratio": 379,
        "revenue": 48382,
        "num_employees": 33312
      },
      {
        "ceo": "David Kemper",
        "company": "Commerce Bancshares",
        "y": 4871971,
        "x": 54058,
        "pay_ratio": 90,
        "revenue": 1289,
        "num_employees": 4755
      },
      {
        "ceo": "James Lally",
        "company": "Enterprise Financial",
        "y": 969702,
        "x": 60000,
        "pay_ratio": 16,
        "revenue": 237,
        "num_employees": 635
      },
      {
        "ceo": "Tim Wentworth",
        "company": "Express Scripts",
        "y": 15895415,
        "x": 52509,
        "pay_ratio": 302.7,
        "revenue": 100065,
        "num_employees": 26600
      },
      {
        "ceo": "Jon Vrabely",
        "company": "Huttig Building Products",
        "y": 926805,
        "x": 47091,
        "pay_ratio": 20,
        "revenue": 753,
        "num_employees": 1300
      },
      {
        "ceo": "Mark Trudeau",
        "company": "Mallinckrodt",
        "y": 15026710,
        "x": 146870,
        "pay_ratio": 102,
        "revenue": 3222,
        "num_employees": 3900
      },
      {
        "ceo": "John Fischer",
        "company": "Olin",
        "y": 7779774,
        "x": 78838,
        "pay_ratio": 91.68,
        "revenue": 6268,
        "num_employees": 6526
      },
      {
        "ceo": "Glenn Kellow",
        "company": "Peabody Energy",
        "y": 20577025,
        "x": 118812,
        "pay_ratio": 173,
        "revenue": 5579,
        "num_employees": 7165
      },
      {
        "ceo": "Jeffrey Davis",
        "company": "Perficient",
        "y": 3761105,
        "x": 96193,
        "pay_ratio": 39.1,
        "revenue": 485,
        "num_employees": 2078
      },
      {
        "ceo": "Anna Manning",
        "company": "Reinsurance Group",
        "y": 7041523,
        "x": 107171,
        "pay_ratio": 66,
        "revenue": 12558,
        "num_employees": 2741
      },
      {
        "ceo": "Ron Kruszewski",
        "company": "Stifel Financial",
        "y": 13228078,
        "x": 143083,
        "pay_ratio": 92,
        "revenue": 2996,
        "num_employees": 8528
      },
      {
        "ceo": "Michael Anderson",
        "company": "Avadel Pharmaceuticals",
        "y": 1861421,
        "x": 91470,
        "pay_ratio": 20,
        "revenue": 173,
        "num_employees": 180
      }
    ]
  }],
  exporting: {
    enabled: false
  },
  credits: {
    enabled: false
  },
});

0 个答案:

没有答案