Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.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 使用google.charts.load一次性加载多个图表类型_Javascript_Google Visualization - Fatal编程技术网

Javascript 使用google.charts.load一次性加载多个图表类型

Javascript 使用google.charts.load一次性加载多个图表类型,javascript,google-visualization,Javascript,Google Visualization,我想用谷歌图表制作一个插件,如下所示: (功能(全局){ "严格使用",; 如果(!global.google | |!global.google.charts){ 设s=document.createElement('script'); s、 src=`//www.gstatic.com/charts/loader.js`; 文件。标题。附录子项; } 让google={}; google.ready=function(\ux){ 设t=setInterval(函数(){ if(global

我想用谷歌图表制作一个插件,如下所示:

(功能(全局){
"严格使用",;
如果(!global.google | |!global.google.charts){
设s=document.createElement('script');
s、 src=`//www.gstatic.com/charts/loader.js`;
文件。标题。附录子项;
}
让google={};
google.ready=function(\ux){
设t=setInterval(函数(){
if(global.google&&global.google.charts){
净间隔(t);
_.call(global.google);
}
}, 1);    
};
let chart=(函数(){
让_selector=Symbol('GoogleChart');
类谷歌图表{
构造函数(选择器){
此[_选择器]=选择器;
}
CoreChart(选项={}){
让_this=this,selector=document.getElementById(_this[_selector]);
设init=function(){
让谷歌=这个;
让drawChart=函数(){
设O={
宽度:options.width | | 500,
高度:options.height | | 500,
图例:options.legend | |{},
pointSize:options.pointSize | | 1,
vAxis:options.vAxis | |{},
hAxis:options.hAxis | |{},
series:options.series |{},
颜色:options.colors | |[],
线宽:选项。线宽| | 2
};
让data=new google.visualization.DataTable();
如果(!options.data | | | |!options.data.columns | |!options.data.rows)抛出“缺少”数据。图表中没有要显示的数据。`;
for(让options.data.columns中的列)data.addColumn(column,options.data.columns[column]);
if(options.tooltip&&options.tooltip.type){
让工具提示={
类型:options.tooltip.type,
角色:“工具提示”
};
if(options.tooltip.isHtml){
工具提示.p={
html:对
};
O.工具提示={
isHtml:是的
};
}
data.addColumn(工具提示);
}
data.addRows(options.data.rows);
//
让chart=newgoogle.visualization.LineChart(选择器);
//
图表绘制(数据,O);
};
load('current',{packages:['corechart']});
google.charts.setOnLoadCallback(drawChart);
};
//
google.ready(init);
}
}
返回谷歌图表;
}());
global.GoogleChart=图表;
}(窗口);
//用法:
let chart=新谷歌图表(‘线’);
查特({
宽度:500,
身高:200,
数据:{
栏目:{
'字符串':'日期',
“编号”:“日期”
},
行:[
['1', 2],
['', 7],
['3', 3],
['', 9],
['5', 3],
['', 1],
['7', 4],
['', 6],
['9', 3],
['', 5],
['11', 8],
['', 2],
['13', 1],
['', 0],
['15', 8]
]
},
图例:{
位置:'顶部'
},
系列:{
0: {
颜色:“#f00”,
lineDashStyle:[2,2,20,2,20,2]
}
},
点数:3
});

您现在可以多次调用google.charts.load。该限制仅适用于旧版本。