首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ChartJs -无法绘制注释线

问ChartJs -无法绘制注释线
EN

Stack Overflow用户
提问于 2019-03-03 05:49:17
回答 1查看 400关注 0票数 0

我试着画平均价格注释,但什么也没发生..价格条也被画出来了,但是,注释没有发生任何变化。另外,我检查了控制台,没有错误或警告

代码语言:javascript
复制
const Chart = require("chart.js");

const ctx = document.querySelector("#canvas").getContext("2d");

new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ["iPhone", "Samsung", "Xiaomi"],
        datasets: [
            {
                data: [1000, 700, 900]
            },
        ]
    },
    options: {
        title: {
            display: true,
            text: "Price Comparison",
            fontSize: 22,
            fontColor: "white",
        },
        legend: {
            display: false
        },

        responsive: true,
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true,
                    display: false
                }
            }],
        }
    },
    plugins: {
        annotation: {
            drawTime: 'afterDatasetsDraw',

            annotations: [{
                type: 'line',
                mode: 'horizontal',
                scaleID: 'y-axis-0',
                value: 750,
                borderColor: 'rgb(75, 192, 192)',
                borderWidth: 4,
                label: {
                    enabled: true,
                    content: 'Average Price'
                }
            }]
        }
    }
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-03 15:26:45

我找到了。我忘记注册插件了。在我使用另一个插件之前,这是不需要手动广告。但是似乎有些插件并不是全局添加的。我们应该手动添加它们。

代码语言:javascript
复制
const Chart = require("chart.js");
const Annotation = require("chartjs-plugin-annotation");
Chart.plugins.register(Annotation);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54963351

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档