javascript - 谷歌图表未显示配置的所有条形图
问题描述
我正在使用谷歌图表,我正在尝试显示“协商”栏,正如您在代码中看到的那样,尽管我将它插入到数组中并且它没有出现在图表中:
我在这里想念什么?
google.charts.load('current', {packages: ['corechart']});
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Negotiation',' Creativity ',' People Management ',' Coordination with Others ',' Orientation to serve ',' Emotional Intelligence ',' Complex Problem Solving ',' Cognitive Flexibility ',' Critical Thinking ',' Taking of Decisions'],
['Líder ', 3, 2, 5, 1 ,3.2, 3.3, 3.1,2.4 ,2.5 ],
['Colaborador', 2, 3, 2.5, 5 ,2.2, 5.1 ,3.6,2.1 ,3 ],
]);
var options = {
title : 'Talento bahia',
legend: {position: 'right', textStyle: {color: 'black', fontSize: 11}},
vAxis: {title: 'Pontuação'},
seriesType: 'bars',
series: {
0: { color: '#631E80' },
1: { color: '#FCE22B' },
2: { color: '#4A308B' },
3: { color: '#011F9B' },
4: { color: '#C81212' },
5: { color: '#AF3423' },
6: { color: '#247D4B' },
7: { color: '#23B634' },
8: { color: '#5EC4FF' },
9: { color: '#F15757' }
}
};
var chart = new google.visualization.ComboChart(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8"/>
<script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<div id = "container" style = "width: 990px; height: 400px; margin: 0 0 -100px 0 auto"></div>
解决方案
您缺少一些数据...
bar 名称数组上的第一个元素类似于数组的规范:
['LABELS', 'Negotiation',' Creativity ',' People Management ',' Coordination with Others ',' Orientation to serve ',' Emotional Intelligence ',' Complex Problem Solving ',' Cognitive Flexibility ',' Critical Thinking ',' Taking of Decisions']
而且您的 2 个数据值数组每个只有 9 个值。在示例中,我再添加一个值 => 15
['Líder ', 15, 3, 2, 5, 1 ,3.2, 3.3, 3.1,2.4 ,2.5 ],
['Colaborador', 15, 2, 3, 2.5, 5 ,2.2, 5.1 ,3.6,2.1 ,3 ],
google.charts.load('current', {packages: ['corechart']});
function drawChart() {
var data = google.visualization.arrayToDataTable([
['LABELS', 'Negotiation',' Creativity ',' People Management ',' Coordination with Others ',' Orientation to serve ',' Emotional Intelligence ',' Complex Problem Solving ',' Cognitive Flexibility ',' Critical Thinking ',' Taking of Decisions'],
['Líder ', 15, 3, 2, 5, 1 ,3.2, 3.3, 3.1,2.4 ,2.5 ],
['Colaborador', 15, 2, 3, 2.5, 5 ,2.2, 5.1 ,3.6,2.1 ,3 ],
]);
var options = {
title : 'Talento bahia',
legend: {position: 'right', textStyle: {color: 'black', fontSize: 11}},
vAxis: {title: 'Pontuação'},
seriesType: 'bars',
series: {
0: { color: '#631E80' },
1: { color: '#FCE22B' },
2: { color: '#4A308B' },
3: { color: '#011F9B' },
4: { color: '#C81212' },
5: { color: '#AF3423' },
6: { color: '#247D4B' },
7: { color: '#23B634' },
8: { color: '#5EC4FF' },
9: { color: '#F15757' }
}
};
var chart = new google.visualization.ComboChart(document.getElementById('container'));
chart.draw(data, options);
}
google.charts.setOnLoadCallback(drawChart);
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta charset="utf-8"/>
<script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
<div id = "container" style = "width: 990px; height: 400px; margin: 0 0 -100px 0 auto"></div>
推荐阅读
- data-mining - 词关联挖掘如何泛化n-gram语言模型
- javascript - 天气 api 密钥不起作用
- google-contacts-api - Google GCM 弃用 - 使用 GCM 令牌的旧移动客户端
- ubuntu - sed 和重命名文件
- javascript - $(this) 不在委托事件处理程序中选择子元素
- c# - 从 ResourceDirectory 绑定到 ViewModel 中的属性
- sql - 如何在 Croud Repository 中查找特定列不同的最后 10 个实体?
- android - 如果我设置的触发时间已经过去,如何让 AlarmManager 不执行我的通知?
- c - Eclipse-Photon 三元算子编译错误
- java - 从迭代器中删除数组中元素的最佳方法是什么?