最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - impossible to remove scale from radar chart (chart.js) - Stack Overflow

programmeradmin6浏览0评论

I have been trying all day to remove the scale of a radar chart in chart js. Although the chart works just fine, nothing seems to be working to remove the scale. Unfortunately the documentation is not that helpful for that issue. here is what the graph looks like. The scale looks the same everytime. Clearing cache from browser does not help either. here is the code for the chart:

function setChart(){

var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
                        type: 'radar',
                        data: {
                            labels: ['classA','classB','classC','classD'],
                            datasets: [{
                                label: 'revenue proportion per class',
                                data: [0.25, 0.3, 0.15, 0.3],
                                backgroundColor: [
                                    'rgba(255, 99, 132, 0.2)',

                                ],
                                borderColor: ['rgba(255, 99, 132, 0.2)'],

                                borderWidth: 5

                            },
                                {

                             label: 'proportion of item quantity per class',
                                data: [0.25, 0.3, 0.15, 0.3],
                                    backgroundColor: [

                                    'rgba(54, 162, 235, 0.2)',


                                ],
                                    borderColor: ['rgba(54, 162, 235, 0.2)'],
                                    borderWidth: 5
                                }
                            ],

and the options:

options: {
                                scale: {

                                    ticks:{ 
                                           label: false,
                                            min: 0,
                                            max: 1,
                                            fixedStepSize: 4,
                                            showLabelBackdrop: false,
                                            fontSize: 0,
                                            color: "#eee"
                                    }
                                }
options: {
                                scale: {

                                    ticks:{ 
                                           display: false
                                    }
                                }

I am doing something stupid? Any help on that would be weled!

I have been trying all day to remove the scale of a radar chart in chart js. Although the chart works just fine, nothing seems to be working to remove the scale. Unfortunately the documentation is not that helpful for that issue. here is what the graph looks like. The scale looks the same everytime. Clearing cache from browser does not help either. here is the code for the chart:

function setChart(){

var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
                        type: 'radar',
                        data: {
                            labels: ['classA','classB','classC','classD'],
                            datasets: [{
                                label: 'revenue proportion per class',
                                data: [0.25, 0.3, 0.15, 0.3],
                                backgroundColor: [
                                    'rgba(255, 99, 132, 0.2)',

                                ],
                                borderColor: ['rgba(255, 99, 132, 0.2)'],

                                borderWidth: 5

                            },
                                {

                             label: 'proportion of item quantity per class',
                                data: [0.25, 0.3, 0.15, 0.3],
                                    backgroundColor: [

                                    'rgba(54, 162, 235, 0.2)',


                                ],
                                    borderColor: ['rgba(54, 162, 235, 0.2)'],
                                    borderWidth: 5
                                }
                            ],

and the options:

options: {
                                scale: {

                                    ticks:{ 
                                           label: false,
                                            min: 0,
                                            max: 1,
                                            fixedStepSize: 4,
                                            showLabelBackdrop: false,
                                            fontSize: 0,
                                            color: "#eee"
                                    }
                                }
options: {
                                scale: {

                                    ticks:{ 
                                           display: false
                                    }
                                }

I am doing something stupid? Any help on that would be weled!

Share Improve this question edited May 12, 2020 at 21:43 Murcielago asked May 12, 2020 at 20:47 MurcielagoMurcielago 1,0051 gold badge14 silver badges36 bronze badges 5
  • that won't help much, would be better if you posted a online demo – EugenSunic Commented May 12, 2020 at 20:48
  • I can do it for sure, how would i do that? – Murcielago Commented May 12, 2020 at 20:49
  • you ve got plenty of options: stakcblitz, codepen, fiddle.js.... – EugenSunic Commented May 12, 2020 at 20:50
  • okok I take a look, in the meantime I add a pic of the graph – Murcielago Commented May 12, 2020 at 20:51
  • @EugenSunic sorry shame on me, I am struggling to the render the graph properly on fiddle.js, I have added, data in the fields on my example to help a bit.. – Murcielago Commented May 12, 2020 at 21:44
Add a ment  | 

2 Answers 2

Reset to default 6
options: {
     scales: {
         r: {
            pointLabels: {
                display: false // Hides the labels around the radar chart
            },
            ticks: {
                display: false // Hides the labels in the middel (numbers)
            }
        }
    }
}

The linear radial axis documentation lists four configuration options (as of v2.9.3):

  • angleLines
  • gridLines
  • pointLabels
  • ticks

Each of these is an object that supports the display property. Specifying display: false in all four objects removes the scale.

options: {
  scale: {
    angleLines: {
      display: false
    },
    gridLines: {
      display: false
    },
    pointLabels: {
      display: false
    },
    ticks: {
      display: false
    },
  }
}

Here's a working example:

new Chart('myChart', {
  type: 'radar',
  data: {
    labels: ['A', 'B', 'C', 'D'],
    datasets: [{
      label: 'Series 1',
      data: [0.25, 0.3, 0.15, 0.3],
    }]
  },
  options: {
    scale: {
      angleLines: {
        display: false
      },
      gridLines: {
        display: false
      },
      pointLabels: {
        display: false
      },
      ticks: {
        display: false
      },
    }
  }
});
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/Chart.min.js"></script>
<canvas id="myChart"></canvas>

发布评论

评论列表(0)

  1. 暂无评论