Highcharts传奇没有显示系列名称

时间:2016-03-15 16:49:52

标签: javascript jquery highcharts

我正在开发一个简单的项目,我正在尝试创建一个图表。除了图例没有显示系列名称这一事实外,一切都很完美。这是fiddle

HTML:

<div id="container" style="height: 400px"></div>

代码:

var myData = [{
 "name": "Beginning Farmer",
 "y": 1,
 "color": "#FAD252"
 }, {
 "name": "Organic",
 "y": 1,
 "color": "#B5C442"
 }, {
 "name": "Whole Farm",
 "y": 2,
 "color": "#EB2F65"
 }];

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

xAxis: {
  categories: myData[0]
},

series: [{
  data: myData,
}]
});
});

enter image description here

我在这里缺少什么?谢谢!

2 个答案:

答案 0 :(得分:4)

要在图例中设置该值,每个系列都需要name属性:

series: [{
    name: 'Foo',
    data: myData,
}]

Updated fiddle

答案 1 :(得分:0)

实际上,我需要做的就是将对象数组myData的格式更改为:

var myData = [{
"name": "Beginning Farmer",
"data": [1],
"color": "#FD31B4"
}, {
"name": "Organic",
"data": [1],
"color": "#A7DC7B"
}, {
"name": "Whole Farm",
"data": [2],
"color": "#67ABDA"
}];

然后:

series选项中,只需将其更改为:

series: myData,

enter image description here