Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将数组中的值放入Zingchart.js_Javascript_Arrays_Stacked Chart_Zingchart - Fatal编程技术网

Javascript 如何将数组中的值放入Zingchart.js

Javascript 如何将数组中的值放入Zingchart.js,javascript,arrays,stacked-chart,zingchart,Javascript,Arrays,Stacked Chart,Zingchart,我想在Zingchart.js中创建堆叠条形图,数据如下: var data = [{ month : 1, name : 'Alex', count : '20' }, { month : 2, name : 'Alex', count : '20' } , { month : 2, name : 'John', count : '30' } , { month : 2, name : 'Jane', count : '25' } , { m

我想在Zingchart.js中创建堆叠条形图,数据如下:

var data = [{
  month : 1,
  name : 'Alex',
 count : '20'
 },
 {
 month : 2,
  name : 'Alex',
 count : '20'
 } ,
 {
 month : 2,
  name : 'John',
 count : '30'
 } ,
 {
 month : 2,
  name : 'Jane',
 count : '25'
 } ,
 {
 month : 3,
  name : 'Alex',
 count : '15'
 } ,
 {  
 month : 3,
  name : 'John',
 count : '25'
 } ,
 {
 month : 3,
  name : 'Jane',
 count : '23'
 } 
}]
我将数据转换为:

var data = {  "Alex" : ["20", " 20", "15"],
              "John" : ["0", "30", "25" ],
              "Jane" : ["0", "25", "23"]
           }
我想将数组中的值放入Zingchart.js,以创建堆叠条形图 以及在zingchart中输入值的示例:

var myConfig={
输入:“酒吧”,
绘图:{
对,,
堆栈类型:“正常”
},
“scale-x”:{
“标签”:[“1”、“2”、“3”],
“标签”:{“offsetY”:5,
“文本”:“月份”,
“fontColor”:“777”,
“字体大小”:14
}
},
系列:[
{
数值:[20,20,15]
},
{
值:[0,30,25]
},
{
值:[0,25,23]
}
]
};
zingchart.render({
id:'我的图表',
资料来源:myConfig,
高度:“100%”,
宽度:“100%”
});
html,body,#myChart{
宽度:100%;
身高:100%;
}

zingchart.MODULESDIR=”https://cdn.zingchart.com/modules/";
ZC.LICENSE=[“569d52cefae586f634c54f86dc99e6a9”,“ee6b7db5b51705a13dc2339db3edaf6d”];

您可以执行以下操作:

var xLabels = Object.keys(data)

var yValues = xLabels.map(function (key) {
  return {
    values: data[key].map(Number)
  }
})
查看此演示:

var数据={
“Alex”:[“20”、“20”、“15”],
“约翰”:[“0”、“30”、“25”],
“简”:[“0”、“25”、“23”]
}
var xLabels=Object.keys(数据)
var series=xLabels.map(函数(键){
返回{
值:数据[键]。映射(编号)
}
})
变量myConfig={
输入:“酒吧”,
绘图:{
对,,
堆栈类型:“正常”
},
“scale-x”:{
“标签”:xLabels,
“标签”:{
“offsetY”:5,
“文本”:“月份”,
“fontColor”:“777”,
“字体大小”:14
}
},
系列:系列
};
zingchart.render({
id:'我的图表',
资料来源:myConfig,
高度:“100%”,
宽度:“100%”
});
html,
身体,
#我的图表{
宽度:100%;
身高:100%;
}

zingchart.MODULESDIR=”https://cdn.zingchart.com/modules/";
ZC.LICENSE=[“569d52cefae586f634c54f86dc99e6a9”,“ee6b7db5b51705a13dc2339db3edaf6d”];

抱歉,如何将数据从
[{values:[20,20,15]},{values:[0,30,25]}]
添加到
[{values:[20,20,15],text:“Alex”},{values:[0,30,25],text:“John”}
尝试以下操作:
xLabels.map(函数(键){return values:data[key].map(Number),text:key}
抱歉再次打扰您。如何将带有逗号“[{values:[2000,20,15],text:“Alex”}]”的数字格式添加到“[{values:[2000,20,15],text:“Alex”}]`