dimple.js如何在不更改数据的情况下更改图表轴的标签?

jpm*_*iaz 3 d3.js dimple.js

假设我们有示例http://dimplejs.org/examples_viewer.html?id=bars_vertical的条形图,我想将x轴标签从"Months"更改为"Meses".我怎样才能做到这一点?

Joh*_*der 7

绘制后,您可以访问标题对象并设置其文本,如下所示:

chart = new dimple.chart(svg, data);
x = chart.addCategoryAxis("x", ["Fruit", "Year"]);
chart.addMeasureAxis("y", "Value");
chart.addSeries(["Volume", "Year"], dimple.plot.bar);
chart.draw();
x.titleShape.text("My New Title");
Run Code Online (Sandbox Code Playgroud)

这是工作:http://jsfiddle.net/y3BVN/


phi*_*ppn 6

您可以绘图之前直接更改标题,而不是绘图更改titleShape .

为此,只需指定title属性:

var chart = new dimple.chart(svg, data);
var x = chart.addCategoryAxis("x", ["Fruit", "Year"]);
x.title = "My New Title";
Run Code Online (Sandbox Code Playgroud)