简体   繁体   English

如何从对象数组中提取jqCharts的数据?

[英]How can I extract data for jqCharts from an array of objects?

How can I extract data for jqCharts from an array of objects? 如何从对象数组中提取jqCharts的数据?

[{
    Catagories: 78, 
    Value1: 78
},{
    Catagories: 5,         
    Value1: 5
},{           
    Catagories: 5, 
    Value1: 5
},{
    Catagories: 79, 
    Value1: 79
}]

I want to do this in javascript. 我想用javascript做。 When I created this data by concatenating strings it does not work. 当我通过连接字符串创建此数据时,它不起作用。 I also tried this but it did not work 我也试过了,但是没有用

JSON.parse(string) 

My code is: 我的代码是:

$.each(datatogen, function (key, value) {
    var datatomo = "";
    $.each(value, function (key1, value1) {
        datatomo = "{Catagories: " + value1 + ", Value1: " + value1 + "}";
    });
    makedatato += datatomo;
});

How can I prepare this type of data? 如何准备此类数据? If it is in string I can convert it into a JSON object? 如果它是字符串形式,我可以将其转换为JSON对象? Please help me. 请帮我。

There is a way that you can prepare your object array. 有一种方法可以准备对象数组。 No need to output as a string, then parse it. 无需输出为字符串,然后解析它。 Please try this: 请尝试以下方法:

var output = [];
$.each(datatogen, function (key, value) {
var datatomo = {};
$.each(value, function (key1, value1) {
  datatomo.Catagories = value1;
  datatomo.Value1 = value1 ;
});
output.push(datatomo);
});

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

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