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

javascript - Chart.js legend position error - Stack Overflow

programmeradmin2浏览0评论

I try to move the legend of a pie chart(created with Chart.js 2.0) to left or right, but I always get an error. The bottom and top option works.

var myChart = new Chart(ctx, {
        type: 'pie',
        data: {
            labels: optionLabels,
            datasets: [{
                label: '# of Resources',
                data: optionData,
                backgroundColor: optionColor,
                borderColor: "white",
                borderWidth: 1,

            }]
        },
        options: {
            legend: {
                position: 'left'
            }
        }
    });

Is there a library bug or something similar?

I try to move the legend of a pie chart(created with Chart.js 2.0) to left or right, but I always get an error. The bottom and top option works.

var myChart = new Chart(ctx, {
        type: 'pie',
        data: {
            labels: optionLabels,
            datasets: [{
                label: '# of Resources',
                data: optionData,
                backgroundColor: optionColor,
                borderColor: "white",
                borderWidth: 1,

            }]
        },
        options: {
            legend: {
                position: 'left'
            }
        }
    });

Is there a library bug or something similar?

Share Improve this question asked Sep 11, 2017 at 7:01 ChrisChris 6,3216 gold badges40 silver badges57 bronze badges 4
  • are you sure the error is occurring due to position: 'left'? coz it doesn't seem like.. – ɢʀᴜɴᴛ Commented Sep 11, 2017 at 8:44
  • @ɢʀᴜɴᴛ I suspect that it occurs on position:left and right also because it does not occur on position: 'top' and position: 'bottom'. The last two works as expected. – Chris Commented Sep 11, 2017 at 8:50
  • @ɢʀᴜɴᴛ The version was 2.2.0, I updated it to 2.7.0 and it works, you can submit your answer. Thanks! – Chris Commented Sep 11, 2017 at 9:06
  • @Chris How to update version 2.2.0 to 2.7.0? – Raj G Commented Aug 23, 2023 at 10:06
Add a ment  | 

1 Answer 1

Reset to default 5

Seems like you are using an old version of ChartJS (which might have this bug).

Make sure you use the latest version of ChartJS, which is 2.7.0 at-the-moment.

see a working example.

发布评论

评论列表(0)

  1. 暂无评论