我目前正在尝试使用Rickshaw小部件在Dashing中将数据类型添加到我的图形的x轴。
基本上我想在仪表板文件中创建与Coffeescript小部件中的if语句相关的数据调用
来自coffeescript的代码(Rickshaw.coffee)
# Define elements for Rickshaw time
time = new Rickshaw.Fixtures.Time
months = time.unit('month')
weeks = time.unit('week')
if @get("weekly-view")
x_axis = new Rickshaw.Graph.Axis.Time(graph: graph, timeUnit: weeks)
y_axis = new Rickshaw.Graph.Axis.Y(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
else if @get("monthly-view")
x_axis = new Rickshaw.Graph.Axis.Time(graph: graph, timeUnit: months)
y_axis = new Rickshaw.Graph.Axis.Y(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
else
x_axis = new Rickshaw.Graph.Axis.X(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
y_axis = new Rickshaw.Graph.Axis.Y(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
这涉及一个调用更改的Dashboard文件:
<li data-row="1" data-col="1" data-sizex="6" data-sizey="6">
<div data-id="etvvrb" data-view="Rickshawgraph" data-weekly-view="true"></div>
</li>
基本上if语句似乎没有任何效果,我已经尝试修改以启用if @get(&#39; var&#39;)== true或其他类似的尝试。
非常感谢任何帮助!
马特
答案 0 :(得分:0)
管理破解它:
# Define elements for Rickshaw time
time = new Rickshaw.Fixtures.Time
months = time.unit('month')
weeks = time.unit('week')
y_axis = new Rickshaw.Graph.Axis.Y(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
switch @get('xAxis')
when "weekly"
x_axis = new Rickshaw.Graph.Axis.Time(graph: graph, timeUnit: weeks)
when "monthly"
x_axis = new Rickshaw.Graph.Axis.Time(graph: graph, timeUnit: months)
else
x_axis = new Rickshaw.Graph.Axis.X(graph: graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
和
<li data-row="1" data-col="1" data-sizex="6" data-sizey="6">
<div data-id="etvvrb" data-view="Rickshawgraph" data-title="Weekly ETV reach" data-moreinfo="Week commencing" style="background-color:#336699" data-color-scheme="rainbow" data-renderer="line" data-x-axis="weekly"></div>
</li>
基本上,&#39; data-x-axis&#39;参数需要传递为@get(&#39; xAxis&#39;)。然后您可以随意在开关元件中随意做。