【问题标题】:Raphael Linechart. Overwrite X Axis. Uncaught TypeError: Object 0 has no method 'attr'拉斐尔线图。覆盖 X 轴。未捕获的类型错误:对象 0 没有方法“attr”
【发布时间】:2014-03-17 22:48:57
【问题描述】:

我尝试以漂亮的格式化日期更新 Raphael LineChart 的 Unix 时间戳,但我收到错误 Uncaught TypeError: Object 0 has no method 'attr'

我使用的代码如下:

  var progression = r.linechart(30, 0, 350, 300, x, y, options);

  console.log("Progression is %O", progression.axis[0].text.items);

  /* Overwrites the Axis label for display a formatted date instead of the Unix timestamp */
  $(progression.axis[0].text.items).each( function ( label, index ) {
      originalText = label.attr('text');
      newText = 'up';
      label.attr({'text': newText});
    });

似乎我无法修改标签,但该属性存在,如此打印屏幕上所示... 突出显示的文本是我的 Unix 时间戳...

我试图直接修改属性,但它不可能......当我打印标签时,它只是一个字符串,而不是一个对象(?)

【问题讨论】:

  • 可以加个小提琴吗?我通常更喜欢我的自定义轴标签。它可以使用 chart.eachColumn 轻松生成。在 eachColumn 中,this.y、this.x 以及 this.value 可用于将文本放置在画布上的任何位置。

标签: graphael


【解决方案1】:

对象 0 没有方法 'attr'

...因为它实际上是'attrs'

【讨论】:

  • 不,抱歉。让我发疯的是函数中争论的倒置。我倒置了标签和索引,它起作用了;-) 解决方案是:
  • $(progression.axis[0].text.items).each( function (index, label) { console.log("label",label); originalText = label.attr('text '); newText = 'up'; label.attr('text', newText); });
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多