Search code examples
d3.jsc3

D3.remove() is not working properly with c3-axis (I don't want to hide it)


I must remove the elements for the axis because I don't want to have empty space. I have to fit the graph in a panel.

enter image description here

I'm trying something like:

enter image description here

d3.select("g.c3-axis .c3-axis-y").remove();
d3.select("g.c3-axis-x").remove();

I printed this following selection in my console and it's all right but the remove doesn't work:

d3.select("svg").select(".c3-axis-x").selectAll("*").remove();

No results! What's the mistake ? I think that when I launch the function the chart is not completely generated, but I can't find a good solution to achieve the style desiderated.


Solution

  • I achieved the result in a different way, I fixed the padding for the axis in the chart.

    enter image description here

    axis: 
            {
                x: 
                {
    
                    type: 'timeseries',
                    tick: 
                    {
                        format : "%d-%m-%y"
                    },
                    show: false,
        padding : 
                    {
                        bottom : 0,
                        left: 0, 
                        right: 0
                    }
    
                },
                y: 
                {
    
                    min: 0,
                    padding : 
                    {
                        bottom : 0,
                        left: 0,
                        right: 0
                    },
                    tick: 
                    {
                        values: [[0], [maxs]],  
                        format:  function (d) { return d3.format(',f')(d) +' kWh/h' }
                    },
                    show: false
                }
            },