在javascript中,我正在渲染一个数据点列表,如下所示:
<ul class="site-stats">
<li>
<div data-title="Cleared Orders" data-pts="[gd(2013, 9 , 9), 3],[gd(2013, 9 , 10), 1],[gd(2013, 9 , 13), 1],[gd(2013, 9 , 16), 1]" class="cc">
<i class="icon=arrow-right"></i>
<strong>6</strong>
<small>Cleared Orders</small>
</div>
</li>
<li>
<div data-title="Customers Added" data-pts="[gd(2013, 9 , 9), 5],[gd(2013, 9 , 10), 2]" class="cc">
<i class="icon=arrow-right"></i>
<strong>7</strong>
<small>Customers Added</small>
</div>
</li>
<li>
<div data-title="Counts Ran" data-pts="[gd(2013, 9 , 9), 8],[gd(2013, 9 , 10), 11],[gd(2013, 9 , 11), 7],[gd(2013, 9 , 12), 1],[gd(2013, 9 , 16), 5]" class="cc">
<i class="icon=arrow-right"></i>
<strong>32</strong>
<small>Counts Ran</small>
</div>
</li>
<li>
<div data-title="Pending Orders" data-pts="" class="cc">
<i class="icon=arrow-right"></i>
<strong>0</strong>
<small>Pending Orders</small>
</div>
</li>
<li>
<div data-title="Failed Orders" data-pts="" class="cc">
<i class="icon=arrow-right"></i>
<strong>0</strong>
<small>Failed Orders</small>
</div>
</li>
<li>
<div data-title="Records Delivered" data-pts="[gd(2013, 9 , 9), 25970],[gd(2013, 9 , 10), 2500],[gd(2013, 9 , 13), 2023],[gd(2013, 9 , 16), 400]" class="cc">
<i class="icon=arrow-right"></i>
<strong>30893</strong>
<small>Records Delivered</small>
</div>
</li>
</ul>
基本上,data-pts 保存了我的浮动图表值。Onclick我想改变我的flot图表的内容:
$(".cc").click(function(e)
{
var data = $(this).data('pts');
console.log(data);
plot.setData([data]);
plot.setupGrid();
plot.draw();
});
当我这样做时,var 数据将作为一个直接向上的字符串返回......真正奇怪的是,console.log(data) 给了我我期望的数组。当然,这会导致浮点图表不刷新新数据......我是否可以将要返回的字符串转换为原始 javascript 数组?我也愿意接受其他建议...
谢谢!