Chart.js编号为许多小数位的Y-AXIS标签格式 [英] Chart.js number Y-AXIS label format for many decimal places

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

问题描述

我遇到chart.js Y轴标签问题。我有以下数据。

I'm having problems with chart.js Y-axis labels. I have the following data.

var data = {
labels: ["1","2","3","4","5"],
datasets: [
    {
        label: "My First dataset",
        fillColor: "rgba(220,220,220,0.5)",
        strokeColor: "rgba(220,220,220,0.8)",
        highlightFill: "rgba(220,220,220,0.75)",
        highlightStroke: "rgba(220,220,220,1)",
        data: [0.15000000000000088,0.15000000000000133,0.15000000000000177,0.15000000000000221,0.15000000000000308]
    },
]
};

我得到了这个结果。

图表结果图片

正如您所见,Y轴上的标签在小数点后第五位被切断。如何在Y轴标签中显示我的数据中的所有小数位?

As you can see the labels in the Y-axis are cut after the fifth decimal place. How do I show all the decimal places from my data in the Y-Axis labels?

TIA。

推荐答案

试试这个

var data = {
labels: ["1","2","3","4","5"],
datasets: [
    {
        label: "My First dataset",
        fillColor: "rgba(220,220,220,0.5)",
        strokeColor: "rgba(220,220,220,0.8)",
        highlightFill: "rgba(220,220,220,0.75)",
        highlightStroke: "rgba(220,220,220,1)",
        data: [15000000000000088,15000000000000133,15000000000000177,15000000000000221,15000000000000308]
    },
]
};

// create chart
var ctx = document.getElementById("radaranalytics").getContext('2d');
var radar = new Chart(ctx).Bar(data, {
  scaleBeginAtZero: false,
  scaleLabel: "<%=value/100000000000000000%>",
  tooltipTemplate: "<%if (label){%><%=label%>: <%}%><%= value/100000000000000000 %>",
});






小提琴 - https://jsfiddle.net/2g794kxh/

请注意,图表中的值将超出限制。有关详细信息,请参阅 https://stackoverflow.com/a/30373552/360067

Note that there will be a rounding off of the values in the chart beyond a limit. See https://stackoverflow.com/a/30373552/360067 for more information.

如果您想避免最好的选择是将您的比例/值的静态部分视为字符串,即您的数据将是88,133,177等,并且您的比例/值前缀将是0.150000 .....

If you want to avoid that your best bet would be to treat the static part of your scale / value as a string i.e. your data would be 88, 133, 177, etc. and your scale / value prefix would be 0.150000.....

这篇关于Chart.js编号为许多小数位的Y-AXIS标签格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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