javascript 带有 x 和 y 轴的 Highcharts 空白图表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14350435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 21:25:29  来源:igfitidea点击:

Highcharts blank chart with x and y axis

javascripthighcharts

提问by Kevin

I want to use highcharts creating a blank chart with no datas but x and y axis. How to do it?

我想使用 highcharts 创建一个没有数据但 x 和 y 轴的空白图表。怎么做?

var chart = new Highcharts.Chart({

    chart: {
        renderTo: 'container'
    },

    yAxis: {        
        labels: {
            formatter: function() {
                return this.value +' km';
            }
        }
    },

    series: [{
        data: []        
    }]

});

it returns

它返回

enter image description here

在此处输入图片说明

But I want to display y-axis with label.

但我想用标签显示 y 轴。

采纳答案by Zaheer Ahmed

You can put data and hide the series after setting property

您可以在设置属性后放置数据并隐藏系列

ignoreHiddenSeries : false

Here is Working DemoIf you hide the series Y-Axis will still be visible.

这是工作演示如果您隐藏系列 Y 轴仍将可见。

回答by Duniyadnd

You can put in your min/max values for the xAxis and yAxis and use null for all data.

您可以输入 xAxis 和 yAxis 的最小值/最大值,并对所有数据使用 null。

Forkedfrom @ZaheerAhmed's response above as I figure it deserves a spot as an alternative solution without needing to hide the data after the fact.

叉形从@如上我算出它值得点作为一种替代的解决方案,而不需要隐藏的事实后的数据ZaheerAhmed的响应。

i.e.

IE

yAxis: {
   min: 1,
   max:
} ,
xAxis: {
   min: 1,
   max: 50
},
series: {
   data:[null,null]
}

回答by dardenfall

FWIW, it seems that highcharts has this functionality built in yAxis.showEmpty

FWIW,似乎highcharts在yAxis.showEmpty中内置了这个功能

Unfortunately, the fiddle listed in the documentation doesn't work, and there is a related open highcharts issue on the matter:

不幸的是,文档中列出的小提琴不起作用,并且有一个相关的开放 highcharts 问题:

no hide y axis

没有隐藏 y 轴

回答by Vahid

Setting min and max for xAxisand yAxisis not a good solution! Because if the data is loaded later (When it's resolved), then you won't have auto calculated min and max. In Highcharts API, it's said:

xAxisand设置 min 和 maxyAxis不是一个好的解决方案!因为如果稍后加载数据(解决后),那么您将不会自动计算最小值和最大值。在Highcharts API 中,它说:

If null, the max value is automatically calculated

如果为空,则自动计算最大值

So you should set min and max back to nullwhen the data is loaded. But in my case setting it to null or even deleting the option, didn't result in automatic calculating (Seems strange).

因此,您应该将 min 和 max 设置回null加载数据时。但在我的情况下,将其设置为 null 甚至删除该选项,并没有导致自动计算(看起来很奇怪)。

What I did instead was setting charts.showAxesto true! That's it. Take a look at the demo provided by Highcharts

我所做的是将charts.showAxes设置为 true!而已。看一下Highcharts提供的demo

Important:You of course need to set series to something like this:

重要提示:您当然需要将系列设置为如下所示:

series: [
  {
    data: [null, null, null]
  },
  {
    data: [null, null, null]
  }
]

Note: Make sure xAxis.showEmptyand yAxis.showEmptyare set true (which is true by default).

注意:确保xAxis.showEmptyyAxis.showEmpty设置为 true(默认情况下为 true)。