c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.35k stars 1.39k forks source link

After render show or hide axis x not working #1520

Open jmtavares opened 8 years ago

jmtavares commented 8 years ago
var chart = c3.generate({
    data: {
        columns: [
            ['data1', 30, 200, 100, 400, 150, 250],
            ['data2', 50, 20, 10, 40, 15, 25]
        ],
        axes: {
            data1: 'y',
            data2: 'y2'
        }
    },
    grid: {
        x: {
            show: true
        }
    }
});

chart.internal.config.axis_x_show=false;

chart.flush();
missingdays commented 8 years ago

Hey! We at Etersoft implemented it in our fork as follows

c3_chart_fn.axis.showX = function (value){
    var $$ = this.internal;

    $$.config.axis_x_show = !!value;
    $$.axes.x.style("visibility", $$.config.axis_x_show ? 'visible' : 'hidden');

    $$.redraw();
};
c3_chart_fn.axis.showY = function (value){
    var $$ = this.internal;

    $$.config.axis_y_show = !!value;
    $$.axes.y.style("visibility", $$.config.axis_y_show ? 'visible' : 'hidden');

    $$.redraw();
};

so chart.axis.showX(true) will make x asix visible, and chart.axis.showX(false) will make it disapear. I will submit PR soon for fixing this issue.

Maybe names will need to be changed, so this methods can be used both as setters and getters.

missingdays commented 8 years ago

Created #1760 to close this