将自定义数据比例添加到Chart.js

时间:2016-06-24 14:16:10

标签: javascript chart.js

我在Chart.js中使用基本图表 - 我想知道是否可以在我的轴上使用自定义比例,例如我希望我的数据点以0-10的数据比例绘制。这可能吗?

<canvas id="myChart" width="150" height="150"></canvas>
<script>
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: 'radar',
    data: {
        labels: ["Staying well", "Looking after yourself", "Where you live", "Feeling safe and being listened to", "Making decisions and managing money", "How you feel"],

        datasets: [{
            label: "Careplan",
            backgroundColor: "rgba(179,181,198,0.2)",
            borderColor: "rgba(179,181,198,1)",
            pointBackgroundColor: "rgba(179,181,198,1)",
            pointBorderColor: "#fff",
            pointHoverBackgroundColor: "#fff",
            pointHoverBorderColor: "rgba(179,181,198,1)",
            data: [5, 8, 9, 4, 6, 6, 5]
        }]
    },
});
</script>

1 个答案:

答案 0 :(得分:2)

查看我的问题并回答HERE

您需要设置scaleStepsscaleStepWidthscaleStartValue。在上面的例子中是:

scaleSteps: 4,
scaleStepWidth: 5,
scaleStartValue: 0

通过4行增加了总共20个。您可以使用这些值来获得所需的效果。