【发布时间】:2017-05-18 08:43:31
【问题描述】:
如何将 Mike Bostock(https://bl.ocks.org/mbostock/7555321) 的标签换行功能添加到我的 nvd3 图表中?
createChart(graph_data, tickValue){
if (graph_data) {
var chart;
nv.addGraph(function () {
var chart = nv.models.multiBarChart()
.reduceXTicks(false) //If 'false', every single x-axis tick label will be rendered.
.rotateLabels(-45) //Angle to rotate x-axis labels.
.showControls(true) //Allow user to switch between 'Grouped' and 'Stacked' mode.
.groupSpacing(0.15) //Distance between each group of bars.
;
chart.xAxis
.tickFormat(function (i) {
return tickValue[i];
});
chart.yAxis
.tickFormat(d3.format(',.1f'));
d3.select('#chart1')
.datum(graph_data)
.call(chart);
return chart;
});
} else {
return <div/>
}
}
tickValue[i] 返回字符串,例如“调用以获取详细信息、首选项和建议汽车”。
我需要包装这个字符串,以便它适合我的图表。
我尝试使用 wrap 函数 (https://bl.ocks.org/mbostock/7555321) 但无法这样做,因为它适用于 d3 而不是 nvd3。
谢谢。
【问题讨论】:
标签: javascript reactjs d3.js nvd3.js