简体   繁体   English

C3js:如何隐藏y轴上的刻度线? Y轴标签被切断

[英]C3js: How to hide ticks on y-axis? Y-Axis label is cut off

How can I hide the ticks on the y-axis? 如何隐藏y轴上的刻度?

I currently achieve it by editing tick.format , as can be seen in this JSFiddle http://jsfiddle.net/DanielApt/bq17Lp02/1/ 我目前通过编辑tick.format实现它,这可以在这个JSFiddle http://jsfiddle.net/DanielApt/bq17Lp02/1/中看到

I'm not happy with this solution, as the y-axis label is being cut off 我对这个解决方案不满意,因为y轴标签被切断了

屏幕截图显示正在切断y轴标签

So how can I hide ticks without having y-axis label being cut off? 那么如何在不切断y轴标签的情况下隐藏刻度?

Thank you for your help in advance! 提前谢谢你的帮助!

1) Try setting axis.y.tick.count to 1, so that no ticks are shown except top, and bottom most. 1)尝试将axis.y.tick.count设置为1,这样除了顶部和底部之外不会显示任何刻度。

2) Or try CSS to get ride of all intermediate ticks except top and bottom one like:- 2)或尝试使用CSS来获取所有中间刻度线,除了顶部和底部之外,如: -

.c3-axis-y .tick {
   display: none;
}

If axis label positioning is an issue try to position it somewhere else like:- 如果轴标签定位是个问题,请尝试将其放置在其他位置,例如: -

axis: {
    x: {
        label: {
            text: 'X Label',
            position: 'outer-center'
            // inner-right : default
            // inner-center
            // inner-left
            // outer-right
            // outer-center
            // outer-left
        }
    },

Here is the working code:- http://jsfiddle.net/chetanbh/24jkmvL5/ 这是工作代码: - http://jsfiddle.net/chetanbh/24jkmvL5/

Reference Url : http://c3js.org/samples/axes_label_position.html 参考网址: http//c3js.org/samples/axes_label_position.html

In the end I used a combination of Chetan 's answer and some further work: 最后,我结合了Chetan的回答和一些进一步的工作:

I hid the ticks with: 我用以下方法隐藏了蜱:

.c3-axis-y .tick {
   display: none;
}

And I set the tick format: 我设置了刻度格式:

axis.y.tick.format = function(){return 'fy'; }
//return characters with both ascenders and descenders

See this JS Fiddle http://jsfiddle.net/DanielApt/etuwo8mz/1/ for the solution in action. 请参阅此JS Fiddle http://jsfiddle.net/DanielApt/etuwo8mz/1/以了解解决方案的实际应用。

In case someone still needs it, I put it in onrendered callback to avoid affecting all charts: 如果有人仍然需要它,我会把它放在onrendered回调中以避免影响所有图表:

onrendered: function() {
      d3.select("#myChartContainer").selectAll(".c3-axis-x .tick line").style("display", "none");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM