自定义工具提示或自定义标签(chart.js 2)?

时间:2018-05-29 10:23:24

标签: javascript tooltip chart.js labels

我需要得到这样的图表,我不知道如何获得它。

chart

我尝试使用自定义工具提示,但我需要同时显示所有这些工具提示。我和chartjs-plugin-datalabels一起尝试过但是标签在画布内部并且看起来很切。

我是否需要为每个数据创建一个html工具提示?

有什么想法吗?

更新:

这是我的代码:

options: {
    responsive: true,
    maintainAspectRatio: true,
    legend: {
        display: false
    },
    animation: {
        animateScale: true,
        animateRotate: true
    },
    cutoutPercentage: 60,
    circumference: 2 * Math.PI,
    showAllTooltips: true,
    tooltips: {
        enabled: false
    },
    plugins: {
        datalabels: {
            backgroundColor: function(context) {
                return context.dataset.backgroundColor;
            },
            borderColor: 'white',
            borderRadius: 50,
            borderWidth: 1,
            anchor: 'end',
            align: 'end',
            color: 'white',
            padding: 10,
            font: {
                weight: 'normal',
                size: '10'
            },
            formatter: function(value, context) {
                var percentageNum = context.chart.data.datasets[0].data[context.dataIndex]
                return percentageNum + '\n  %';
            }
        }
    }
}

这就是我得到的:

enter image description here

0 个答案:

没有答案
相关问题