为什么不使用jQuery(简易饼图)设置数据属性



使用Easy Pie Chart,我试图用JSON中的值更改attribut数据百分比的值,但使用我在jQuery(3.5.1(中通常使用的方法,在这种情况下不起作用,我不知道为什么。

我试图设置数据百分比的DIV是:

<div class="chart easy-pie-chart-1" id="ConversionCostPercentage" data-percent="">
<span class="percent1"></span>
</div>

jQuery我试图用设置值:

$('#ConversionCostPercentage').attr('data-percent', thejson.ConversionCostPercentage);

$('#ConversionCostPercentage').data('percent', thejson.ConversionCostPercentage);

执行console.log(json.ConversationCostPercentage(此时返回55。。有人知道线索吗?

在@RoryMacCrossan的推动下,我朝着正确的方向解决了这个问题。。我去了Easy Pie Chart GitHub网站,查看了文档,发现了3个jQuery的小例子(https://github.com/rendro/easy-pie-chart#jquery-1( 这导致使用以下内容,修复了它:

$('.chart').data('easyPieChart').update(thejson.ConversionCostPercentage); 

最新更新