如何使用d3.js处理条形图中的值log 0?

时间:2014-07-07 02:20:38

标签: javascript d3.js bar-chart c3.js

我尝试使用d3.js(+ c3.js)来显示数据。在右y轴我需要一个条形图的对数刻度。我按照https://github.com/masayuki0812/c3/issues/252提示,他们工作了!

但问题是当我在数据集中有数据0时,它会使条形图无法显示。我尝试通过修改处理扩展的函数来处理这个问题:

for(var i=1; i<data_test_original.length; i++){
    if (data_test_original[i] === 0){
        data_logscale_tweet[i] = 0;
    }
    else {
        data_logscale_tweet[i] = Math.log(data_test_original[i]) / Math.LN10; 
    }      
}

这是我的数据集:

data_test_original = ['data3', 0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,3,2,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,7,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,15,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,12,0,41,0,4,0,5,0,29,0,0,0,0,0,0,0,0,0,0,0,11,0,19,23,87,0,83,0,17,13,36,0,10,1,6,0,2,0,1,3,0,0,9,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0,3,0,0,0,1,0,0,1,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,2,0,0,0,43,9,10,9,2,0,0,0,0,1,4,0,0,2,0,9,2,0,0,0,0,0,1,0,0,3,0,0,0,0,0,0,0,1,0,0,0,0,0,2,0,4,0,0,0,6,0,8,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,30,50,100]

您可以查看此http://jsfiddle.net/paE7D/10/

中的图表

您可以在此图表图表中看到,对于数据值0,值1显示在条形图中。我的问题是:如果数据值0?

,如何将条形图值设置为0(不是1)

0 个答案:

没有答案