Chart.js-格式化Y轴 [英] Chart.js - Formatting Y axis

查看:66
本文介绍了Chart.js-格式化Y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Chart.js 绘制简单的条形图,我需要像这样格式化其Y轴

I'm using Chart.js to draw a simple bar plot and I need to format its Y axis like


123456.05至123456,05 $

123456.05 to 123 456,05 $

我不不了解如何使用 scaleLabel:<%= value% >

I don't understand how to use scaleLabel : "<%=value%>"

我看到了有人指向 JS微型模板

,但不知道如何通过我们的 scaleLabel 选项使用。

I saw someone pointing to "JS Micro-Templating",
but no clue how to use that with our scaleLabel option.

有人知道吗如何格式化这个Y轴,也许给我一个例子?

Does someone know how to format this Y axis, and maybe give me an example ?

推荐答案

我有同样的问题,我认为在 Chart.js 2.xx ,方法如下所示。

I had the same problem, I think in Chart.js 2.x.x the approach is slightly different like below.

ticks: {
    callback: function(label, index, labels) {
        return label/1000+'k';
    }
}

更多详细信息

var options = {
    scales: {
        yAxes: [
            {
                ticks: {
                    callback: function(label, index, labels) {
                        return label/1000+'k';
                    }
                },
                scaleLabel: {
                    display: true,
                    labelString: '1k = 1000'
                }
            }
        ]
    }
}

这篇关于Chart.js-格式化Y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆