【发布时间】:2016-12-16 09:10:51
【问题描述】:
尝试做这个图表对于 0 来说很重要,我需要从 0 开始,而不是从 650 开始,如图所示。
我做错了什么?,我无法解决:
看这里的图表图像
<canvas id="myChart2015_5853aee63b981" width="500" height="500" style="display: block; width: 500px; height: 500px;"></canvas>
<script style="text/javascript">
var ctx = document.getElementById("myChart2015_5853aee63b981");
var myChart2015_5853aee63b981 = new Chart(ctx, {
type: 'bar',
data: {
labels: ["Trimestre 1", "Trimestre 2", "Trimestre 3", "Trimestre 4"],
datasets: [
{backgroundColor:['rgba(255, 99, 132, 0.2)','rgba(255, 99, 132, 0.2)','rgba(255, 99, 132, 0.2)','rgba(255, 99, 132, 0.2)'],borderColor:['rgba(255, 99, 132, 1)','rgba(255, 99, 132, 1)','rgba(255, 99, 132, 1)','rgba(255, 99, 132, 1)'],
type: 'bar',
label: 'Total de pacientes',
data: [712,913,1030,1091],
options: { tension:0.0, bezierCurve:false },borderWidth: 1,tension:0.25 },
{backgroundColor:['rgba(204, 230, 255,0.2)'],borderColor:['rgba(2, 173, 80,1)'],
type: 'line',
label: 'Límite superior',
data: [700,700,700,700],
options: { tension:0.0, bezierCurve:false },borderWidth: 1,tension:0.25 },
{backgroundColor:['rgba(36, 143, 36,0)'],borderColor:['rgba(75, 172, 198,1)'],
type: 'line',
label: 'Meta',
data: [700,700,700,700],
options: { tension:0.0, bezierCurve:false },borderWidth: 1,tension:0.25 },
{backgroundColor:['rgba(51, 51, 26,0)'],borderColor:['rgba(182, 87, 8,1)'],
type: 'line',
label: 'Límite inferior',
data: [650,650,650,650],
options: { tension:0.0, bezierCurve:false },borderWidth: 1,tension:0.25 }
],
options: {
tension:0.0,
scaleBeginAtZero: true,
scaleStartValue: 0,
scale: {
reverse:true,
ticks: {
beginAtZero: true
}
}
}
}});
</script>
Chart.js 的文档说:
options: {
scale: {
reverse: true,
ticks: {
beginAtZero: true
}
}
}
});
// This will create a chart with all of the default options, merged from the global config,
// and the Radar chart defaults but this particular instance's scale will be reversed as
// well as the ticks beginning at zero.
【问题讨论】:
-
我需要从零开始的行,而不是那里的那个槽......
-
您提到和使用的文档部分是针对雷达图的,它没有 x 轴或 y 轴(它只有一个从中心向外的刻度)。查看具有
scales ... yAxes ... ticks ... beginAtZero ...部分的文档,因为您有一个 y 轴,并且您需要这个从零开始。
标签: javascript php jquery charts chart.js