简体   繁体   中英

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:

<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:

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

Updated fiddle

Actually all I needed to do was to change the format of the object array myData to:

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: myData,

在此处输入图片说明

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