• chartjs显示数值标签插件:chartjs-plugin-datalabels


    Getting Started

    #Installation

    #npm

    npm npm downloads

    npm install chartjs-plugin-datalabels --save
    

    This plugin can also be installed using Bower.

    #CDN

    jsdelivr jsdelivr hits

    By default, https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels returns the latest (minified) version, however it's highly recommended to always specify a version in order to avoid breaking changes. This can be achieved by appending @{version} to the url:

    https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@1.1.2    // exact version
    https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@1        // latest 1.x.x
    

    Read more about jsDeliver versioning on their website.

    #Download

    github github downloads

    You can download the latest version of chartjs-plugin-datalabels from the GitHub releases:

    • chartjs-plugin-datalabels.js (recommended for development)
    • chartjs-plugin-datalabels.min.js (recommended for production)
    • chartjs-plugin-datalabels.zip (contains .js and .min.js versions + samples)

    #Integration

    #HTML

    <script src="https://cdn.jsdelivr.net/npm/chart.js@2.7.3/dist/Chart.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0"></script>
    

    IMPORTANT

    chartjs-plugin-datalabel must be loaded after the Chart.js library!

    Once imported, the plugin is available under the global property ChartDataLabels. This is useful to register/unregister the plugin afterward.

    #Module

    import Chart from 'chart.js';
    import ChartDataLabels from 'chartjs-plugin-datalabels';
    

    #Registration

    This plugin registers itself globally, meaning that once imported, all charts will display labels. In case you want it enabled only for a few charts, you first need to unregister it globally:

    // NOTE: when imported as a <script> tag, use the global property 'ChartDataLabels'
    Chart.plugins.unregister(ChartDataLabels);
    

    Then, you can enabled the plugin only for specific charts:

    var chart = new Chart(ctx, {
        plugins: [ChartDataLabels],
        options: {
            // ...
        }
    })
    

    See also Chart.js › Using plugins.

    DEPRECATION

    From version 1.x, this plugin will no longer be registered automatically (see #42 for details).

    #Configuration

    The plugin options can be changed at 3 different levels and are evaluated with the following priority:

    • per dataset: dataset.datalabels.*
    • per chart: options.plugins.datalabels.*
    • or globally: Chart.defaults.global.plugins.datalabels.*

    For example:

    // Change default options for ALL charts
    Chart.helpers.merge(Chart.defaults.global.plugins.datalabels, {
        color: '#FE777B'
    });
    
    var chart = new Chart(ctx, {
        options: {
            plugins: {
                // Change options for ALL labels of THIS CHART
                datalabels: {
                    color: '#36A2EB'
                }
            }
        },
        data: {
            datasets: [{
                // Change options only for labels of THIS DATASET
                datalabels: {
                    color: '#FFCE56'
                }
            }]
        }
    });
  • 相关阅读:
    React学习 之 阶段性小作品(待办事项_已完成事项 CRUD)
    React 学习之 键盘事件 表单事件 事件对象以及React中的ref获取dom节点 、React实现类似Vue的双向数据绑定
    mysql 时间戳 今天 昨天 7天 30天 及未来时间
    mysql历史数据自动归档
    配置nginx支持跨域访问
    AWK 简明教程
    shell 生成指定范围随机数与随机字符串
    Linux下Shell的for循环语句
    系统部署安装工具 WinToHDD Enterprise v4.2
    格式工厂 FormatFactory v5.1.0.0
  • 原文地址:https://www.cnblogs.com/xbzhu/p/11610796.html
Copyright © 2020-2023  润新知