Hello everyone,
I've searched a bit here and on the examples page, but haven't found anything about logarithm-scaled axes. Is it possible to create them? If not, consider this as a feature request.
Best regards,
Yakov.
Hi, Sorry currently not. Now you need to generate the logarithm-scaled data by yourself and plot.
I'll consider as a new feature later.
Hello Masayuki,
you need to generate the logarithm-scaled data
do you mean that it's possible to emulate this feature now? I've looked through the #Axis examples, but haven't noticed a way to put the ticks in arbitrary positions.. What example should I look into?
Best regards and thanks for your time and your work,
Yakov.
When you prepare your data convert into log scale. In Python let's say you have a list like this
[100,1000,10000]
You just do this
import math
log_list = map(math.log10,[100,1000,10000])
An implementation of Masayuki's workaround:
data_test_original = ['data1', 10, 100, 1000, 3, 500, 50, 5, 3000]
data_test = ['data1'];
for(var i=1; i<data_test_original.length; i++){
data_test[i] = Math.log(data_test_original[i]) / Math.LN10;
}
var chart_test = c3.generate({
bindto: '#chart_test',
size: {
height: 240,
width: 480
},
data: {
columns: [
data_test
]
},
axis : {
y : {
tick: {
format: function (d) { return Math.pow(10,d).toFixed(2); }
}
}
},
});
hai @pbustosl ,,it's work for me!thx...but when i have value 0 in data1, it's not work, how can i handle value 0 ? thanks
the following would also format the values:
data_test_original = ['data1', 10, 100, 1000, 3, 500, 50, 5, 3000]
data_test = ['data1'];
for(var i=1; i<data_test_original.length; i++){
data_test[i] = Math.log(data_test_original[i]) / Math.LN10;
}
var chart_test = c3.generate({
size: {
height: 240,
width: 480
},
data: {
type:"bar",
columns: [
data_test
],
labels : {show:true,
format: {
data1 : function(d,id){console.log(id, Math.pow(10,d));return Math.pow(10,d).toFixed(0);}
}
}
},
axis : {
y : {
show:false,
tick: {
format: function (d) { return Math.pow(10,d).toFixed(0); }
}
}
},
});
that's a pretty ugly hack. would it be possible to expose an API that allows any d3 scale to be plugged in?
+1 ...I need to draw a chart in log scale.
I would also like the ability to set my y axis(es) to by log
I too would like to be able to use a log scale for the y axis.
Any news on this?
Tried to tackle this issue (#2100). This is not 100% perfect but it may be sufficient for a lot of cases.
I tried @pbustosl workaround... it was helpful.
but when the data value is 1, the y axis was starting from 1 . also when the data value was 0 chart was not rendering.
i have done some workaround for that.
please refer this JSFiddle https://jsfiddle.net/86chryat/
d3.js directly supports log scale on an axis, so it'd be really nice if that could be surfaced in c3. It's a much nicer solution than recomputing the data, because it also handles the ticks.
I agree log scale would be useful
@masayuki0812 - by closing this, does it mean you won't consider support for it? It's really a critical feature for certain applications. It would be great to have proper integration if you have the time / inclination please.
Most helpful comment
that's a pretty ugly hack. would it be possible to expose an API that allows any d3 scale to be plugged in?