在ng2图表中隐藏未使用的轴

时间:2016-10-16 07:44:14

标签: angular typescript chart.js ng2-charts

我正在使用两个Y轴(左右) 当我为其中一个隐藏所有已使用的数据集时,刻度线(轴标签)将变为1到-1。

我想在不使用时隐藏轴或标签,有什么想法吗?

隐藏之前: Both Y Axes used

隐藏后: Right Y-Axis Changed - Not used

选项>音阶:

        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'} }
          ]

在文档中没有找到任何内容。

2 个答案:

答案 0 :(得分:2)

   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
    }
]
}


   };``

答案 1 :(得分:0)

您可以在代码中隐藏轴。只需添加一个角度on-mouseover事件,并将显示设置为true / false,并带有否定条件!条件​​:

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