【发布时间】:2021-10-08 06:25:17
【问题描述】:
我有一个 Chartjs 脚本,例如:
<script type="text/javascript">
var dataname = @Html.Raw(Json.Serialize(ViewBag.performancename));
var dataquo = @Html.Raw(Json.Serialize(ViewBag.performancequo));
var datapo = @Html.Raw(Json.Serialize(ViewBag.performancepo));
var ctx = document.getElementById('canvasx5');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: dataname,
datasets: [{
label: 'QUO',
fill: true,
backgroundColor: [
'rgba(255, 99, 132, 0.8)'
],
borderColor: [
'rgba(255, 99, 132, 1)'
],
borderWidth: 1,
data: dataquo
}
,
{
label: 'PO',
fill: true,
backgroundColor: [
'rgba(75, 192, 192, 0.8)'
],
borderColor: [
'rgba(75, 192, 192, 1)'
],
borderWidth: 1,
data: datapo
}]
},
borderWidth: 1,
options: {
legend: {
display: true,
}
,
scales: {
xAxes: [{
stacked: false,
barPercentage: 0.8,
gridLines: {
offsetGridLines: true
}
}],
yAxes: [{
stacked: false,
ticks: {
beginAtZero: true,
stepSize: 2,
min: 0
}
}]
}
}
});
</script>
结果类似于:
每个var 的值是:
dataname: ['Arif','Choirul','Rexy']
dataquo: [2,2,1]
datapo: [0,0,3]
他们在Array 结果上。
为什么第二个和第三个标签的颜色不同?我的脚本有问题吗?需要帮助和建议。
谢谢。
【问题讨论】:
-
datapo、dataquo、dataname的值是什么
-
@Strella,请更新问题。请检查。谢谢。
-
backgroundColor: ['rgba(75, 192, 192, 0.8)', 'rgba(75, 192, 192, 0.8)', 'rgba(75, 192, 192, 0.8)'] , borderColor: [ 'rgba(75, 192, 192, 1)', 'rgba(75, 192, 192, 1)', 'rgba(75, 192, 192, 1)' ], .... 仅用于测试。
标签: javascript jquery linq razor chart.js