【问题标题】:ChartKick gem passing through hashChartKick gem 通过哈希
【发布时间】:2015-03-22 00:09:48
【问题描述】:

我正在使用ChartKick ruby gem 并想知道如何传入一个参数来调整百分比字体大小并隐藏第二个百分比的文本。

 <%= pie_chart({"Watched" => 45.9, nil => 54.1}, :library => {:colors => ["#1ac6ff", "#ECECEB"], :legend => 'none', :fontSize => '35px'}) %>

我引用了 this 并且可以通过执行 pieSliceText: 'none' 来隐藏这两个百分比,但无法弄清楚如何让它只适用于第二个百分比。 fontSize 参数也没有调整字体大小。有什么建议吗?

我希望蓝色右侧的百分比文本更大,左侧的百分比文本隐藏。

【问题讨论】:

    标签: ruby-on-rails hash charts chartkick


    【解决方案1】:

    fontSize 必须指定为数字。尝试:fontSize =&gt; 10:fontSize =&gt; 20等,让蓝色右侧的百分比文本更大。

    看起来不可能在显示另一个百分比文本的同时完全隐藏一个百分比文本。

    以下使其显示具有不同字体的两个文本。不幸的是,将字体大小设置为 0 不起作用。

    <%= pie_chart({"Watched" => 45.9, nil => 54.1}, 
        :library => {
           :legend => 'none', 
           :slices => [
             {color: "#1ac6ff", textStyle: {fontSize: 20}}, 
             {color: "#ECECEB", textStyle: {fontSize: 10}}
           ]
        }) 
    %>
    

    您可以通过将颜色设置为transparent 来隐藏整个切片,如下所示:

    <%= pie_chart({"Watched" => 45.9, nil => 54.1}, 
           :library => {
             colors: ["#1ac6ff", "transparent"],
             legend: 'none',    
             fontSize: 20
      }) 
    %>
    

    【讨论】:

    • 奇怪,当我尝试我的字体根本不会显示时。
    • 它生成这个 HTML
    • 猜猜我不能使用我使用的相同语法。将您的语法与完整块一起使用。谢谢
    • fontSize=35 也没有为我显示任何内容;我猜可以使用的字体大小有上限。
    猜你喜欢
    • 1970-01-01
    • 2011-08-20
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 1970-01-01
    相关资源
    最近更新 更多