Skip to content

Logarithmic plot #252

Closed
Closed
@YakovL

Description

@YakovL

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.

Activity

masayuki0812

masayuki0812 commented on May 21, 2014

@masayuki0812
Member

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.

YakovL

YakovL commented on May 22, 2014

@YakovL
Author

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.

gourneau

gourneau commented on Jun 11, 2014

@gourneau

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])
pbustosl

pbustosl commented on Jun 25, 2014

@pbustosl

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); }
            }
        }
    },
});
ihsansatriawan

ihsansatriawan commented on Jul 5, 2014

@ihsansatriawan

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

abrin

abrin commented on Sep 22, 2015

@abrin

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); }
            }
        }
    },
});
robertlevy

robertlevy commented on Apr 8, 2016

@robertlevy

that's a pretty ugly hack. would it be possible to expose an API that allows any d3 scale to be plugged in?

Leprosy

Leprosy commented on Jun 23, 2016

@Leprosy

+1 ...I need to draw a chart in log scale.

NullVoxPopuli

NullVoxPopuli commented on Jul 9, 2016

@NullVoxPopuli

I would also like the ability to set my y axis(es) to by log

ericsvendsen

ericsvendsen commented on Aug 19, 2016

@ericsvendsen

I too would like to be able to use a log scale for the y axis.

ergo

ergo commented on Nov 8, 2016

@ergo

Any news on this?

panthony

panthony commented on Jul 11, 2017

@panthony
Contributor

Tried to tackle this issue (#2100). This is not 100% perfect but it may be sufficient for a lot of cases.

bhavikboricha009

bhavikboricha009 commented on Apr 12, 2018

@bhavikboricha009

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/

JetForMe

JetForMe commented on Mar 27, 2020

@JetForMe

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.

AbeHandler

AbeHandler commented on Apr 4, 2020

@AbeHandler

I agree log scale would be useful

adrianbj

adrianbj commented on May 29, 2020

@adrianbj

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: A feature request or an enhancementC-new-chartCategory: A feature request for a new chart

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @gourneau@ergo@abrin@NullVoxPopuli@panthony

        Issue actions

          Logarithmic plot · Issue #252 · c3js/c3