【问题标题】:Problems with variables in dynamic Morris.js graph building动态 Morris.js 图形构建中的变量问题
【发布时间】:2013-01-17 15:02:31
【问题描述】:

我正在尝试使用 Morris.js 和 Raphael.js 构建一个图表 基本上我希望 JQuery 从我的页面中获取一个值,计算 100 与该值之间的差值并构建图形......

我的html:

<div id="donut-example">81</div>

我的 jquery:

var perc = $('div#donut-example').text();
var perc2 = 100 - perc;
Morris.Donut({
element: 'donut-example',
data: [
{label: "Abbiamo raccolto il", value: perc},
{label: "Ci resta da raccogliere il", value: perc2},
],
colors: ['#D58025','#37619d']
});

请检查这个 jsfiddle:http://jsfiddle.net/HeNCQ/5/

基本上,如果我将 Morris.donut 函数中的值强制为数字,它会很好地工作并构建完整的甜甜圈图,但如果我将值放入变量中,则该图没有意义,因为这两个值很小。

【问题讨论】:

    标签: jquery variables options morris.js


    【解决方案1】:

    你应该给值变量整数。因此,一个快速而肮脏的解决方法是将 perc 转换为整数:

    perc = parseInt(perc);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多