Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding unused axis in ng2-charts

I'm using two Y axes (right and left) When I hide all the used datasets for one of them, the ticks (Axis labels) turn to 1 to -1.

I want to to hide the axis or the labels when it is not used, any ideas?

Before Hiding: Both Y Axes used

After Hiding: Right Y-Axis Changed - Not used

Options>Scales:

        yAxes: [
            {type: "linear", id: "y-axis-0", display: true, position: "right",gridLines:{display: false},
            scaleLabel:{display: true, labelString: 'mBar'}},
            {type: "linear", id: "y-axis-1", display: true, position: "left",ticks: {beginAtZero:true},
            scaleLabel:{display: true, labelString: 'Knots/°C'} }
          ]

Didn't find anything in the documentation.

like image 552
Niv Avatar asked Aug 31 '25 22:08

Niv


2 Answers

   If you want to remove the x axis and y axis data so to do that you need 
        to use scales and put in bar-chart-demo.ts file and inside export
          class you have to paste like that what  i mentioned below 
             and it worked . 

 public barChartOptions:any = {
  scaleShowVerticalLines: false,
     animation: false,
     scaledisplay:false,
     responsive: true,

scales: {
   xAxes: [
    {
        display: false
    }
  ],
   yAxes: [
      {
        display: false
    }
]
}


   };``
like image 98
RAHUL KHARBANDA Avatar answered Sep 03 '25 19:09

RAHUL KHARBANDA


You can hide the axis in your code. Just add an angular on-mouseover event and set the display to true/false with negation !condition:

scales: {
    xAxes: [
        {
            display: false
        }
    ],
    yAxes: [
        {
            display: false
        }
    ]
}
like image 38
Victor Velchev Avatar answered Sep 03 '25 17:09

Victor Velchev