Browse Source

Show formatted value in bar text - #45

pull/51/head
Masayuki Tanaka 11 years ago
parent
commit
d8286e498a
  1. 11
      c3.js

11
c3.js

@ -139,8 +139,7 @@
// tooltip - show when mouseover on each data // tooltip - show when mouseover on each data
var __tooltip_enabled = getConfig(['tooltip', 'enabled'], true), var __tooltip_enabled = getConfig(['tooltip', 'enabled'], true),
__tooltip_contents = getConfig(['tooltip', 'contents'], function (d) { __tooltip_contents = getConfig(['tooltip', 'contents'], function (d) {
var yFormat = __axis_y_tick_format ? __axis_y_tick_format : function (v) { return +v; }, var xFormat = getXAxisTickFormat(),
xFormat = getXAxisTickFormat(),
text, i, title, value, name; text, i, title, value, name;
for (i = 0; i < d.length; i++) { for (i = 0; i < d.length; i++) {
if (! d[i] || ! isValue(d[i].value)) { continue; } if (! d[i] || ! isValue(d[i].value)) { continue; }
@ -151,7 +150,7 @@
} }
name = d[i].name; name = d[i].name;
value = yFormat(d[i].value); value = formattedValue(d[i].value);
text += "<tr class='-tooltip-name-" + d[i].id + "'><td class='name'><span style='background-color:" + color(d[i].id) + "'></span>" + name + "</td><td class='value'>" + value + "</td></tr>"; text += "<tr class='-tooltip-name-" + d[i].id + "'><td class='name'><span style='background-color:" + color(d[i].id) + "'></span>" + name + "</td><td class='value'>" + value + "</td></tr>";
} }
@ -894,6 +893,10 @@
function subxx(d) { function subxx(d) {
return subX(d.x); return subX(d.x);
} }
function formattedValue(v) {
var yFormat = __axis_y_tick_format ? __axis_y_tick_format : function (v) { return +v; };
return yFormat(v);
}
function findSameXOfValues(values, index) { function findSameXOfValues(values, index) {
var i, targetX = values[index].x, sames = []; var i, targetX = values[index].x, sames = [];
@ -2238,7 +2241,7 @@
.attr('dy', '.32em') .attr('dy', '.32em')
.style("stroke", 'none') .style("stroke", 'none')
.style("opacity", 0) .style("opacity", 0)
.text(function (d) { return d3.format(',.2f')(d.value); }) .text(function (d) { return formattedValue(d.value); })
.attr("class", classTextBar); .attr("class", classTextBar);
mainBarTxt mainBarTxt
.style("opacity", initialOpacity) .style("opacity", initialOpacity)

Loading…
Cancel
Save