这是我的代码.我需要在x和y轴刻度中将初始值设置为"0".我尝试过最新的版本比例选项.
graphOptions = {
///Boolean - Whether grid lines are shown across the chart
scaleShowGridLines: false,
tooltipTitleTemplate: "<%= label%>",
//String - Colour of the grid lines
scaleGridLineColor: "rgba(0,0,0,.05)",
//Number - Width of the grid lines
scaleGridLineWidth: 1,
//Boolean - Whether to show horizontal lines (except X axis)
scaleShowHorizontalLines: true,
//Boolean - Whether to show vertical lines (except Y axis)
scaleShowVerticalLines: true,
//Boolean - Whether the line is curved between points
bezierCurve: true,
//Number - Tension of the bezier curve between points
bezierCurveTension: 0.4,
//Boolean - Whether to show a dot for each point
pointDot: true,
//Number - Radius of each point dot in pixels
pointDotRadius: 4,
//Number - Pixel width of point dot stroke
pointDotStrokeWidth: 1,
pointHitDetectionRadius: 20,
datasetStroke: true,
datasetStrokeWidth: 2,
datasetFill: true,
legendTemplate: "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<datasets.length; i++){%><li><span style=\"background-color:<%=datasets[i].strokeColor%>\"></span><%if(datasets[i].label){%><%=datasets[i].label%><%}%></li><%}%></ul>"
};
var LineChart = new Chart(ctx).Line(graphData, graphOptions);
}
Run Code Online (Sandbox Code Playgroud)
Wou*_*bie 75
现在(5 年后的 3.x 版本)有点不同
options: {
scales: {
y: {
beginAtZero: true
}
}
}
Run Code Online (Sandbox Code Playgroud)
请参阅: https: //www.chartjs.org/docs/latest/#creating-a-chart
如果您需要将其用作默认配置,只需放置min: 0在 node 内部defaults.scale.ticks,如下所示:
defaults: {
global: {...},
scale: {
...
ticks: { min: 0 },
}
},
Run Code Online (Sandbox Code Playgroud)
参考:https : //www.chartjs.org/docs/latest/axes/
请添加此选项:
//Boolean - Whether the scale should start at zero, or an order of magnitude down from the lowest value
scaleBeginAtZero : true,
Run Code Online (Sandbox Code Playgroud)
(参考:Chart.js)
注意:我发布的原始解决方案是针对 Highcharts 的,如果您不使用 Highcharts,请删除标签以避免混淆
| 归档时间: |
|
| 查看次数: |
75690 次 |
| 最近记录: |