设置雷达图的步长大小。

huangapple go评论121阅读模式
英文:

set stepSize for radar chart

问题

我已经使用了这个雷达图表(radar chart.js)。

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
    var options = {
        elements: {
            line: {
                borderWidth: 3
            }
        },
        scales: {
            r: {
                grid: {
                    lineWidth: 4
                },
                angleLines: {
                    lineWidth: 6
                },
                suggestedMin: 0,
                suggestedMax: 100,
            },
        },
    };

    var ctx = document.getElementById('myChart');

    var ChartData = {
        labels: [
            'Eating',
            'Drinking',
            'Sleeping',
            'Designing',
            'Coding',
            'Cycling',
            'Running'
        ],
        datasets: [{
            label: 'My First Dataset',
            data: [65, 59, 10, 21, 56, 55, 40],
            fill: true,
            backgroundColor: 'rgba(255, 99, 132, 0.2)',
            borderColor: 'rgb(255, 99, 132)',
            pointBackgroundColor: 'rgb(255, 99, 132)',
            pointBorderColor: '#fff',
            pointHoverBackgroundColor: '#fff',
            pointHoverBorderColor: 'rgb(255, 99, 132)'
        }, {
            label: 'My Second Dataset',
            data: [28, 48, 40, 19, 36, 27, 10],
            fill: true,
            backgroundColor: 'rgba(54, 162, 235, 0.2)',
            borderColor: 'rgb(54, 162, 235)',
            pointBackgroundColor: 'rgb(54, 162, 235)',
            pointBorderColor: '#fff',
            pointHoverBackgroundColor: '#fff',
            pointHoverBorderColor: 'rgb(54, 162, 235)'
        }]
    };

    var myRadar = new Chart(ctx, {
        type: 'radar',
        data: ChartData,
        options: options
    });
</script>

我想要为刻度设置步长(stepSize),所以我将它包含在 r 部分中。

var options = {
    elements: {
        line: {
            borderWidth: 3
        }
    },
    scales: {
        r: {
            grid: {
                lineWidth: 4
            },
            angleLines: {
                lineWidth: 6
            },
            suggestedMin: 0,
            suggestedMax: 100,
            ticks: {
                stepSize: 20, // 步长的数值
            },
        },
    },
};

但是它不起作用,会产生以下错误:

无法确定轴的类型。请提供 'axis' 或 'position' 选项。

你如何设置雷达图(radar chart)的步长(stepSize)取决于你使用的 Chart.js 版本。在 Chart.js 版本 4.2.1 中,设置步长需要使用正确的配置选项。请检查文档或更新到更高版本的 Chart.js,以查看如何正确设置步长。

英文:

I have used this radar chart.js

  &lt;script src=&quot;https://cdn.jsdelivr.net/npm/chart.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
var options = {
elements: {
line: {
borderWidth: 3
}
},
scales: {
r: {
grid: {
lineWidth: 4
},
angleLines: {
lineWidth: 6
},
suggestedMin: 0,
suggestedMax: 100,
},                
},            
};
var ctx = document.getElementById(&#39;myChart&#39;);
var ChartData = {
labels: [
&#39;Eating&#39;,
&#39;Drinking&#39;,
&#39;Sleeping&#39;,
&#39;Designing&#39;,
&#39;Coding&#39;,
&#39;Cycling&#39;,
&#39;Running&#39;
],
datasets: [{
label: &#39;My First Dataset&#39;,
data: [65, 59, 10, 21, 56, 55, 40],
fill: true,
backgroundColor: &#39;rgba(255, 99, 132, 0.2)&#39;,
borderColor: &#39;rgb(255, 99, 132)&#39;,
pointBackgroundColor: &#39;rgb(255, 99, 132)&#39;,
pointBorderColor: &#39;#fff&#39;,
pointHoverBackgroundColor: &#39;#fff&#39;,
pointHoverBorderColor: &#39;rgb(255, 99, 132)&#39;
}, {
label: &#39;My Second Dataset&#39;,
data: [28, 48, 40, 19, 36, 27, 10],
fill: true,
backgroundColor: &#39;rgba(54, 162, 235, 0.2)&#39;,
borderColor: &#39;rgb(54, 162, 235)&#39;,
pointBackgroundColor: &#39;rgb(54, 162, 235)&#39;,
pointBorderColor: &#39;#fff&#39;,
pointHoverBackgroundColor: &#39;#fff&#39;,
pointHoverBorderColor: &#39;rgb(54, 162, 235)&#39;
}]
};
var myRadar = new Chart(ctx, {
type: &#39;radar&#39;,
data: ChartData,
options: options
});
&lt;/script&gt;

I want to set the stepSize for ticks, so I included this in r section

  var options = {
elements: {
line: {
borderWidth: 3
}
},
scales: {
r: {
grid: {
lineWidth: 4
},
angleLines: {
lineWidth: 6
},
suggestedMin: 0,
suggestedMax: 100,
},
ticks: {
stepSize: 20, // the number of step
}, 
},             
};

but it doesn't work and gives th fllowing error

> Cannot determine type of '' axis. Please provide 'axis' or
> 'position' option.

how can i set stepSize for radar chart v.4.2.1?

答案1

得分: 1

在代码中,"Ticks object should be inside r" 可以翻译为 "Ticks 对象应该位于 r 内部"。

英文:

Ticks object should be inside r

var options = {
elements: {
line: {
borderWidth: 3
}
},
scales: {
r: {
grid: {
lineWidth: 4
},
angleLines: {
lineWidth: 6
},
suggestedMin: 0,
suggestedMax: 100,
ticks: {
stepSize: 20
}
}
},             
};

huangapple
  • 本文由 发表于 2023年3月12日 18:48:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75712588.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定