0

I have tried using d3.js (+c3.js) for visualize data. In right y-axis I need a log scale for barchart. I have followed tips from https://github.com/masayuki0812/c3/issues/252, and they worked!

But the problem is when I have data 0s in the dataset, it makes the barchart not show. I tried to handle this, by modifying the function that handles scaling like this:

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; 
    }      
}

This is my dataset:

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]

You can view chart from this http://jsfiddle.net/paE7D/10/

You can see in this chart chart, for data values 0, values 1 are displayed in the barchart. My question is: How can I set the barchart value to 0 (not to 1), for data values 0?

VividD
  • 10,456
  • 6
  • 64
  • 111
ihsansat
  • 503
  • 2
  • 7
  • 20
  • A log scale should only ever be used with positive numbers. If you have a zero or negative numbers, log scale makes no sense (zero should be shown as negative infinity, and negative numbers cannot be shown at all). – Amadan Jul 07 '14 at 02:27
  • hmm,,,thx...but when i try using matlab, log 0 can be handle, maybe you know a tricky to handling this case using d3.js :) – ihsansat Jul 07 '14 at 02:28
  • You can set it to some appropriately very negative number, like `-1337` instead of to `0`. It's still incorrect, but it looks more-or-less as it should. – Amadan Jul 07 '14 at 02:31
  • thx @Amadan,,,i will try your suggest :) – ihsansat Jul 07 '14 at 02:35
  • I edited a little bit your question to make it clearer. Hope I did not scrxwxd something up. Please check. – VividD Jul 07 '14 at 09:15

0 Answers0