Use an array of objects for serial data in Highcharts

I have an array of objects that I want to display in highcharts. Each object has a name and a value.

I tried to get this to work by doing

var objects = objectArray[]; // objectArray being an array of the objects I want data on
var objectNames = nameArray[]; // This being an array of all the names of the objects
var objectValues = valueArray[]; // An array of all the values of the objects


 series: [{
    data: objects.value,
    name: objects.name
 }]

It blew me up. So I tried to build the series as follows:

 series: [{
    data: objectValues,
    name: objectNames
 }]

This gave me data for the values, but the name was all of the names in the objectNames array ... for each individual piece of data. so I tried to use

series: [{
    data: objectValues
},
{   
    data: objectNames
}]

As a result, a diagram appeared for objectValues, and in the legend - another option for names - which is completely unacceptable, because it makes no sense to have a series of labels, right?

, , foreach, . http://www.highcharts.com/docs/getting-started/how-to-set-options/ , " ".

, , - highcharts, , "" , . ? , highcharts ""?

+4
2

, .

$.each(item, function (index, value) {
    objects.push([value.name, value.value]);
});

series: [{
     data: objects,
     name: 'Value Type Description'
}]

, " " , , .

http://api.highcharts.com/highcharts#series, , .

EDIT: .

, series, data name. name data, .

data - /.

data: [
   {[key1, value1]}, 
   {[key2, value2]}, 
   {[key3, value3]}
]

name - , "" - , " ".

, , " ", , , , Key1 Value1.

+5
        data: [{
            name: 'Point 1',
            y: 1,
            test1:9,
            test2:'ddaf'
        }, {                         ------->      right
            name: 'Point 2',
            y: 5,
            test1:12,
            test2:'ddddaf'
        }]

        data: [{
            my_name: 'Point 1',
            y: 1,
            test1:9,
            test2:'ddaf'
        }, {                         -------> we change 'name' to 'my_name',
            my_name: 'Point 2',               then the name you want to show become
            y: 5,                             'Slice', instead of 'Point 1','Point 2'
            test1:12,
            test2:'ddddaf'
        }]

        data: [{
            my_name: 'Point 1',
            my_y: 1,
            test1:9,
            test2:'ddaf'
        }, {                         ------->  Now,we get nothing.
            my_name: 'Point 2',
            my_y: 5,
            test1:12,
            test2:'ddddaf'
        }]

, "" "" - .

+5

Source: https://habr.com/ru/post/1542202/


All Articles