c3.js y axis min/max not working
Asked Answered
I

1

10

I'm trying to create a chart with percentages in c3.js, but the y axis range seems to be broken. No matter what I do, the min/max values seem to to add 15 to what I enter.

The code included below plots things from 0 to ~15. If I set the y max to 10, it starts to go up to 25. It is infuriating.

    <script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="/js/c3.js"></script>
<script>
  var chart = c3.generate({
    data: {
      columns: [
        ['PC', 0.038, 0.067],
        ['Tablet', 0.038, 0.056],
        ['Mobile',0.027,0.039]
      ],
      type: 'bar',
      labels: {
        format: {
            y: d3.format(".1%"),
        }}
    },
    axis: {
      x: {
        type: 'categorized',
        categories: ['Unique Click Rate','Total Click Rate']
      },
      y: {
        max: .1,
        min: 0
    }
    },
    bar: {
      width: {
        ratio: 0.5,

      },
    }
  });

  setTimeout(function () {
    chart.data.colors({PC: '#2C9AB7',Tablet: '#FEBE12', Mobile: '#DB3A1B'});
  }, 1000);

</script>
Imperial answered 15/9, 2014 at 22:25 Comment(0)
I
22

Found out that the axis has a default padding value. This code fixed it.

      y: {
        max: .1,
        min: 0,
        padding: {top: 0, bottom: 0}
    }
Imperial answered 15/9, 2014 at 22:32 Comment(1)
Where do I send the check? That's been bugging me for weeks!Kort

© 2022 - 2024 — McMap. All rights reserved.