Custom tick size on axis (d3js)

前端 未结 2 1159
时光取名叫无心
时光取名叫无心 2020-12-05 15:50

I am creating a svg x-y-chart in d3.js. Is it possible to create ticks of different lengths depending on tickValue?

I have made my own tickFormat function myTi

2条回答
  •  抹茶落季
    2020-12-05 16:03

    Variant on the answer that suits my requirements. Picked the values I just wanted tick marks for instead of ticks and value, added the "hide" class. But this can be used for any variation on the theme.

                var gy = humiditySVG.append( "g" )
                    .attr( "class", "y axis" )
                    .attr( "transform", "translate(" + 154 + "," + 0 + ")" )
                    .call( yAxis );
    
                humiditySVG.selectAll( "text" )
                    .attr( "class", function ( d ) {
                                               if ( $.inArray(d, [0,50,100])==-1  ) {
                                   return "hide";
                               }
                               return;
                           } );
                humiditySVG.selectAll( "line" )
                    .attr( "x2", function ( d ) {
                               if ( $.inArray(d, [0,50,100])==-1  ) {
                                   return 1;
                               } else {
                                   return 3;
                               }
                               return;
                           } );
    

提交回复
热议问题