簡體   English   中英

使用Chartkick gem和Google圖表繪制線性函數

[英]Drawing linear function by using Chartkick gem and Google chart

我試圖通過在我的rails應用程序上使用Chartkick gem和google chart來繪制線性函數(例如y = ax + b)。

“ a”和“ b”將作為參數給出。

問題是我正在嘗試使用Google圖表在斜率“ a”和“ b”之外實現無限線圖,但我不知道如何以正確的方式實現這一目標。

我想出了繪制帶有兩個點(-b / a,0)和(0,b)的折線圖的解決方案,並在其上提供了趨勢線選項。

<!-- y = 0.55x floatify(2,@datas[4][2]) + 1.47 floatify(2,@datas[3][2]) -->
<%= line_chart [
               {name: "targets",
                data: [
                   ["#{-(@datas[3][2].to_f/@datas[4][2].to_f).round(2)}",0],
                   [0,"#{@datas[3][2].to_f}"]
                ]
               },
           ],
           library: {
               title: "#{@simplereg.variable_name}",
               subtitle: "#{@simplereg.data_name}",
               legend: "right",
               vAxis: {title: 'average'},
               trendlines: {
                  0: {
                      type: 'exponential',
                      visibleInLegend: true
                  }
                }
           }
%>

但是,rails無法讀取“ 0”值作為趨勢線的一種選擇,這與Google圖表文檔所說的不同。 -> https://developers.google.com/chart/interactive/docs/gallery/trendlines我不知道如何解決此代碼。

請幫助我...我不介意拋出這段代碼並以完全不同的方式編寫。

謝謝你

使用如下所示的內容

 <%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %> <%= line_chart [ {name: "targets", data: [ ["-2/3",0], [0,"2"] ] }, ], library: { title: "ABC", subtitle: "XYZ", legend: "right", vAxis: {title: 'average'}, trendlines: { "0"=> { type: 'exponential', visibleInLegend: true } } } %> 

基本上代替symbo 0:使用“ 0” =>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM