我正在使用基于Sinatra的框架进行一个名为Dashing的项目。我的项目的一部分是使用RickShaw图创建一个图表。我的问题是我无法在X轴上显示月名和日期。我正在使用coffeescript来呈现这些值。下面是图的代码:
class Dashing.Graph extends Dashing.Widget
@accessor 'points', Dashing.AnimatedValue
@accessor 'current', ->
return @get('displayedValue') if @get('displayedValue')
points = @get('points')
if points
points[points.length - 1].y
#ready is triggered when ever the page is loaded.
ready: ->
container = $(@node).parent()
# Gross hacks. Let's fix this.
width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1)
height = (Dashing.widget_base_dimensions[1] * container.data("sizey"))
@graph = new Rickshaw.Graph(
element: @node
width: width
height: height
renderer: @get("graphtype")
series: [
{
color: "#fff",
data: [{x:0, y:0}]
}
]
)
@graph.series[0].data = @get('points') if @get('points')
time = new Rickshaw.Fixtures.Time()
days = time.unit("day")
x_axis = new Rickshaw.Graph.Axis.Time(
graph: @graph
timeUnit: days
)
y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
@graph.render()根据我从这里提供的Rickshaw图形API中了解到的情况:
https://github.com/shutterstock/rickshaw/blob/master/src/js/Rickshaw.Fixtures.Time.js
它说你可以指定单位名称。因此,在这个例子中,我使用"day“只是为了测试的原因,但这似乎不起作用。任何帮助都会很好。
发布于 2014-02-22 02:50:40
您可以指定一个timeFixture,它驱动x轴上的滴答如何被标记。
var xAxis = new Rickshaw.Graph.Axis.Time( {
graph: graph,
timeFixture: new Rickshaw.Fixtures.Time.Local()
} );夹具负责显示的时间范围,并触发日期/时间格式的适当详细级别,例如从年份放大到小时。
您还可以创建自己的“时间夹具”并将其设置在那里,查看一下Rickshaw.Fixtures.Time或Rickshaw.Fixtures.Time.Local
或者,指定要显示的固定间距(即“单元”):
var timeFixture = new Rickshaw.Fixtures.Time();
var unitHour = timeFixture.unit('hour');
var xAxis = new Rickshaw.Graph.Axis.Time( {
graph: graph,
timeUnit: unitHour,
timeFixture: timeFixture
} );https://stackoverflow.com/questions/21765960
复制相似问题