Rails,Chartkick:在图表上显示值 [英] Rails, Chartkick: Show values on the charts

查看:81
本文介绍了Rails,Chartkick:在图表上显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过


column_chart @stats




我希望这些值显示在图表。在饼图中,我希望数字244和43在饼图的内部或外部都可见。在柱形图中,我想将值放在顶部或栏中。



关于饼图,已经有一个



编辑2:Chartkick提出了三种安装Chartkick的方法。我选择了Chart.js作为第一个。由于有帮助,我现在安装了第二种方法。现在,我的饼图中显示了数字。

解决方案

我尝试过此方法,并且效果很好

 <%data = [[''Task','每天的小时数'],
['Work',11],
['Eat',2],
['Commute',2],
['Watch TV',2],
['Sleep',7]]%>

<%= pie_chart数据,库:{pieSliceText:值}%>



@institutions 的结构是什么,可能是引起一些问题的原因。



更新::在柱形图上



Chartkick的GH表示,尚无官方支持在每个柱形上显示数据,但
https://github.com/ankane/chartkick.js/issues/38#issuecomment-271117774


The Chartkick gem lets you create many kinds of charts. Currently, my charts look like this:

pie_chart @institutions

column_chart @stats

I want that values are shown on the charts. In the pie chart, I want the number 244 and 43 be visible in or outside of the pie chart. In the column chart, I'd like to have the values on top or in the column. Is this somehow possible?

Regarding to the pie chart, there is already a stackoverflow-question, but the accepted answer does nothing for me:

pie_chart visits.group(:country).count, library: {pieSliceText: 'value-and-percentage'}

I tried to add the option

library: {pieSliceText: 'value-and-percentage'}

but nothing changed. What am I doing wrong? Is there maybe an option or setting that I am missing?

There is another, similar stackoverflow-question, in which following solutions were proposed:

<%= pie_chart @my_data, library: { pieSliceText: 'value' } %>

and

pie_chart graph_data, { pieSliceText: 'value' }

But both didn't work for me. Is there maybe a new syntax?

EDIT 1:

<% data = [['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]] %>

<%= pie_chart data, library: { pieSliceText: 'value' } %>

gives me this:

EDIT 2: Chartkick proposes 3 ways to install Chartkick. I chose the first one with Chart.js. Due to the helpful comments, I now installed the second way. Now, my Pie-Charts have numbers shown.

解决方案

I tried this and it is working fine

<% data = [['Task', 'Hours per Day'],
          ['Work',     11],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]] %>

<%= pie_chart data, library: { pieSliceText: 'value' } %>

What is the structure of @institutions, may be that's causing some issue.

UPDATE:: on column chart

The GH for chartkick says there is no official support for showing data on each column yet https://github.com/ankane/chartkick.js/issues/38#issuecomment-271117774

这篇关于Rails,Chartkick:在图表上显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆