Я разработал Java-приложение с C3 js для рисования графики. В подсказке C3 js я пытаюсь напечатать число с минимальными цифрами в 4 цифры. Я тестирую приложение в нескольких средах, на рабочем столе и на мобильных устройствах (IOS и Android), но в Android - номер из всплывающей подсказки, который он напечатал всего за 3 цифры.
Вот мой js-код, который C3 js использует для рисования всплывающей подсказки:
tooltip: {
grouped: false,
contents: function(d, defaultTitleFormat, defaultValueFormat, color) {
var $$ = this, config = $$.config, titleFormat = config.tooltip_format_title || defaultTitleFormat, nameFormat = config.tooltip_format_name
|| function(name) {
return name;
}, valueFormat = config.tooltip_format_value || defaultValueFormat, text, i, title, value, name, bgcolor;
for (i = 0; i < d.length; i++) {
if (!(d[i] && (d[i].value || d[i].value === 0))) {
continue;
}
if (!text) {
title = titleFormat ? titleFormat(d[i].x) : d[i].x;
text = "<table class='" + $$.CLASS.tooltip + "'>"
+ (title || title === 0 ? "<tr><th colspan='2'>" + title + "</th></tr>" : "");
}
name = nameFormat(d[i].name);
var fundName = dojo.query('#hiddenFundName')[0].value;
var raiffeisenAcumulareFundName = 'raiffeisen acumulare';
if (fundName.toLowerCase() == raiffeisenAcumulareFundName) {
value = valueFormat(d[i].value.toLocaleString("en-US", {
minimumFractionDigits: 6
}), d[i].ratio, d[i].id, d[i].index);
} else {
value = valueFormat(d[i].value.toLocaleString("en-US", {
minimumFractionDigits: 4
}), d[i].ratio, d[i].id, d[i].index);
}
bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id);
var initialNAV = dojo.attr(query("#initialnavPU")[0], "value");
text += "<tr class='" + $$.CLASS.tooltipName + "-" + d[i].id + "'>";
text += "<td class='value'>" + '<h5>' + titleFormat(d[i].x) + '</h5>' + '<h5>Valoarea unitatii de fond: ' + value
+ '</h5>' + '<h5>Randament: ' + ((d[i].value / initialNAV - 1) * 100).toFixed(2) + '%' + '</h5></td>';
text += "</tr>";
}
return text + "</table>";
}
}
Вы знаете, почему мой номер не учитывает количество цифр цифр, которые я хочу напечатать? Помните, что это только на ОС Android.
Попробуйте добавить формат для всплывающей подсказки:
tooltip: {
format: {
value: function (value) {
return d3.format('.4f')(value);
}
},
...
// your current options
}