使用 Chartkick gem 和 Google 图表绘制线性函数

Drawing linear function by using Chartkick gem and Google chart

我正在尝试在我的 rails 应用程序上使用 Chartkick gem 和 google 图表绘制线性函数(如 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
    }
    }
    }
%>

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