简体   繁体   English

Highcharts图例未显示系列名称

[英]Highcharts legend not showing series names

I'm working on a simple project, and I'm trying to create a chart. 我正在做一个简单的项目,并且试图创建图表。 Everything works perfectly except the fact that the legend is not showing the series name. 除了图例未显示系列名称的事实外,其他所有内容都可以正常运行。 This is the fiddle . 这是小提琴

HTML: HTML:

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

Code: 码:

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,
}]
});
});

在此处输入图片说明

What am I missing here? 我在这里想念什么? Thanks! 谢谢!

To set that value in the legend each series needs a name property: 要在图例中设置该值,每个系列都需要一个name属性:

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

Updated fiddle 更新的小提琴

Actually all I needed to do was to change the format of the object array myData to: 实际上,我所需要做的就是将对象数组myData的格式更改为:

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

And then: 接着:

In the series option, just change it to: series选项中,只需将其更改为:

series: myData,

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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