C3.js change label position of Line Chart Y axis to center up of Y axis

℡╲_俬逩灬. 提交于 2019-12-12 20:26:23

问题


I need to change the Y axis's label position upon the Y axis, the current six position options can't meet my scenario, I also tried to customize it with d3 but still without luck.

I created a plnkr demo, and also submit an issue in github.

  var chart = c3.generate({ 
  data: {
      columns: [
          ['data', 30, 200, 100, 400, 150, 250]
      ]
  },
  axis: {
      y: {
          label: {
              text: 'Y Axis Label',
              position: 'outer-top'
          } 
      }
   }
 });

Does any one know how to do it?

Thanks very much in advance.


回答1:


Unlike what you said, you can customize it with D3. Just select the label (by class) and set the transform:

d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")

here is the demo:

// Code goes here
(function() {

  var chart = c3.generate({
    padding: {
      top: 10
    },
    data: {
      columns: [
        ['data', 30, 200, 100, 400, 150, 250]
      ]
    },
    axis: {
      y: {
        label: {
          text: 'Y Axis Label',
          position: 'outer-top'
        }
      }
    }
  });

  d3.select(".c3-axis-y-label").attr("transform", "translate(25,30)")


})();
<head>
  <link rel="stylesheet" href="https://unpkg.com/c3@0.4.14/c3.css">
  <link rel="stylesheet" href="style.css">
  <script src="https://unpkg.com/d3@3.5.6/d3.js"></script>
  <script src="https://unpkg.com/c3@0.4.14/c3.js"></script>
</head>

<body>
  <div id="chart"></div>
  <script src="script.js"></script>
</body>


来源:https://stackoverflow.com/questions/45141524/c3-js-change-label-position-of-line-chart-y-axis-to-center-up-of-y-axis

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!