Javascript 从我的页面上的span更新饼图的值

Javascript 从我的页面上的span更新饼图的值,javascript,jquery,pie-chart,Javascript,Jquery,Pie Chart,我正在使用饼图脚本,并试图从页面上的span更新值 饼图如下所示: HTML 这是我尝试更新数据百分比值的方式,但它不起作用: $('.percentage').attr('data-percent', $(this).closest('.newValue').html()); 使用完整的工作示例 $('.percentage').data(“percent”,$('.newValue').html()) 或 $(this).closest('.newValue').html()的计算结果为

我正在使用饼图脚本,并试图从页面上的span更新值

饼图如下所示:

HTML

这是我尝试更新数据百分比值的方式,但它不起作用:

$('.percentage').attr('data-percent', $(this).closest('.newValue').html());
使用完整的工作示例

$('.percentage').data(“percent”,$('.newValue').html())


$(this).closest('.newValue').html()
的计算结果为
未定义,这导致饼图无法更新。只需将值更改为
$('.newValue').html()
即可更新图表。

感谢您的回答,但这仍然无法更新图表。我添加了带有已加载饼图脚本的JSFIDLE,以便您可以看到它live@DearBee我昨天没能接到你的电话。。我已经更新了答案,它无法获取类newValue
$的最接近值(this)。最近('.newValue')。html()
的计算结果为未定义,这导致饼图无法更新。只需将值更改为
$('.newValue').html()
就是在更新图表。我会被诅咒的。你介意把它贴出来作为答案吗?这样我就可以投票支持你了
$('.percentage').easyPieChart({
  animate: 1000,
  lineWidth: 8,
  barColor: '#00aeef',
  scaleColor: 'transparent',
  onStep: function(value) {
    this.$el.find('span').text(Math.round(value));
  },
  onStop: function(value, to) {
    this.$el.find('span').text(Math.round(to));
  }
});
$('.percentage').attr('data-percent', $(this).closest('.newValue').html());
$('.percentage').attr('data-percent', $('.newValue').html());