我想制作下面那种曲线,但是它对Ipad不起作用。 颜色显示为灰色。
这是 ChartJS 的错误还是我们可以做些什么?
当 type 的值为“line”时,我遇到了这个问题。
当 type 的值为“bar”时,它适用于 Ipad。
您知道处理这个问题的方法吗?
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.bundle.min.js"></script>
<div class="chart-container" style="position: relative; margin-top:30px; height:60vh; width:90vh">
<canvas id="myChart"></canvas>
最佳答案
问题来自 backgroundColor 和 borderColor 中的列表。
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: 'rgba(255, 159, 64, 0.2)',
borderColor: 'rgba(255,99,132,1)',
borderWidth: 1
}
确实,对于等于 bar 的 kind,我们可以为每个标签设置一种颜色。
对于那种“线”,似乎我们不能有一个只有一个值的列表。
我们只能在曲线下使用一种颜色,在边框上使用一种颜色。
关于javascript - iPad 上的曲线颜色是深灰色,而不是红色。如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46051005/