javascript - Chart.js 水平条网格线颜色
问题描述
我已经在我的 ASP.Net MVC 应用程序中向您介绍了出色的 chart.js 库。
首先,用于图表的顶级插件。我正在使用版本版本:2.7.2
现在是我目前正在努力解决的主要问题。
首先是代码。
@{
ViewBag.Title = "Home Page";
}
<div class="container">
<canvas id="myChart" width="400" height="60"></canvas>
</div>
<script src="~/Scripts/Chart.js"></script>
<script>
var ctx = document.getElementById("myChart").getContext('2d');
var myChart = new Chart(ctx, {
type: "horizontalBar",
data: {
labels: ["Totals"],
datasets: [
{ label: "A", data: [1800], backgroundColor: "rgba(165, 97, 125, 1.0)" },
{ label: "B", data: [1800], backgroundColor: "rgba(239, 195, 77, 1.0)" },
{ label: "C", data: [1800], backgroundColor: "rgba(70, 89, 71, 1.0)" },
{ label: "D", data: [900], backgroundColor: "rgba(82, 103, 161, 1.0)" },
{ label: "E", data: [2400], backgroundColor: "rgba(161, 132, 82, 1.0)" },
{ label: "F", data: [1300], backgroundColor: "rgba(82, 160, 161, 1.0)" }
]
},
options: {
scales: {
xAxes: [
{
barThickness: 13,
ticks: {
min: 0,
max: 11000,
stepSize: 3000,
display: true,
beginAtZero: false,
fontSize: 9,
color: "rgba(0, 0, 0, 1.0)",
callback: function (value, index, values) {
var q = value / 100;
return q + 'k';
}
},
gridlines: {
display: false,
},
stacked: true
}
],
yAxes: [{
gridlines: {
color: 'rgba(0,0,0,1)'
},
display: true,
stacked: true
}]
}
}
});
</script>
简单的独立示例,它确实产生了一个堆叠的水平条。
我的问题是我希望更改 yAxes 网格线的颜色,上面的代码显示 rgb(241,241,241) 的颜色,而不是定义的颜色。
配置是文档中描述的方式。
任何人都可以通过展示我做错了什么来提供帮助吗?
解决方案
我相信您需要将gridlines
属性更改为gridLines
,它会按预期工作!
下面是工作的 codepen 示例。
请参阅Aman Sharma ( @amanboss9 ) 在CodePen上 的 Pen ChartJS Axis 颜色。推荐阅读
- r - 如何将一个df的列中的每个值与R中另一个df的列中的每个值进行比较?具有不同行号的dfs
- json - 错误:不能将参数类型“int”分配给参数类型“String”
- sql-server - 为什么使用增量变量更新会创建重复值?
- ios - 在主 StackView 中嵌入的 ScrollView 中嵌入 StackView
- html - 如何让输入字段与文本区域并排放置,而不是重叠?
- pdf - 无法在 Intellij IDEA 中查看 pdf
- jdbc - IIB 没有找到 jdbc 驱动程序
- python - 如何从继承类的方法扩展列表
- apache-spark - 如何从 pyspark 的结构字段中删除 NULL?
- jquery - 捕获事件并防止触发后代码执行