2014-09-23 54 views
0

我正在使用jqplots生成条形图。我能够为整个数字生成精确的图表。但是我无法为具有小数点的值生成图表。下面是我用的代码:如何绘制JQPlot条形图中的十进制值?

<script type="text/javascript"> 
$(document).ready(function(){ 
$.jqplot.config.enablePlugins = true; 
var s1 = ['1.5','3.0', '0.0', '0.0', '0.0', '3.0', '0.0']; 
var ticks = ['New mould', 'Raw Material', 'color/size', 'Imported/Catalogue' , 'Printing' , 'plating' , 'other']; 
plot1 = $.jqplot('chart1', [s1], {  
// Only animate if we're not using excanvas (not in IE 7 or IE 8)..   
animate: !$.jqplot.use_excanvas,  
seriesDefaults:{   
renderer:$.jqplot.BarRenderer,   
pointLabels: { show: true }   
},  
axes: {   
xaxis: {  
renderer: $.jqplot.CategoryAxisRenderer,  
ticks: ticks    
}, 
yaxis: { tickOptions: { formatString: '%.2f' } } 
}, highlighter: { show: false } 
});   
$('#chart1').bind('jqplotDataClick',function (ev, seriesIndex, pointIndex, data) 
{    
$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);   
}  
); 

}); 

</script> 

我收到erroe如下:

这个[R] ._蜱[0]未定义 http://blrsrigwd11074.itcinfotech.com:81/Windchill/netmarkets/javascript/report/plugins/jqplot.pointLabels.min.js 线57

请帮帮我在这个问题上。

回答

3

我可以通过首先查看代码来发现错误。 但我不确定,如果这是错误的真正原因。

您正在使用的数据阵列作为var s1 = ['1.5', '3.0', '0.0', '0.0', '0.0', '3.0', '0.0']; jqPlot试图读取从数据阵列中的值,并且它期待一个IntegerDecimal值(S)。

就你而言,你正在传递String值到数组中。所以你所要做的就是从值中删除单引号('')。

数组应该是这样的,var s1 = [1.5, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0]; //Remove quotes

为了证实这一点,我跑你的代码通的jsfiddle。这里是链接JSFiddle Code

尝试两个小提琴中的数组,引号(var s1 = ['1.5', '3.0', '0.0', '0.0', '0.0', '3.0', '0.0'];)和不带引号(var s1 = [1.5, 3.0, 0.0, 0.0, 0.0, 3.0, 0.0])的值。单引号的不会绘制条形图。

希望它有帮助。

+0

谢谢:)你是对的:) – galme 2014-09-25 06:32:29