我目前正在使用Dashing,我需要将javascript代码转换为coffescript才能使用人力车图库。 (根据本网站上的源代码http://code.shutterstock.com/rickshaw/examples/x_axis.html)
我正在尝试在图表上设置自定义的x轴。
默认Coffescript代码= x_axis = new Rickshaw.Graph.Axis.X(graph: @graph)
要转换的JS代码
var format = function(n) {
var map = {
0: 'zero',
1: 'first',
2: 'second',
3: 'third',
4: 'fourth'
};
return map[n];
}
var x_ticks = new Rickshaw.Graph.Axis.X( {
graph: graph,
tickFormat: format
} );
进入coffescript
var format = function(n) {
var map = {
0: 'zero',
1: 'first',
2: 'second',
3: 'third',
4: 'fourth'
};
return map[n];
}
x_axis = new Rickshaw.Graph.Axis.X(graph: @graph,tickFormat: format)//Make use of format
答案 0 :(得分:0)
format = (n)->
map =
0: 'zero',
1: 'first',
2: 'second',
3: 'third',
4: 'fourth'
map[n]