首页 > 解决方案 > 我们可以在 highcharts 中将图表的 Y 轴值显示为字符串值吗?

问题描述

在我的场景中,对于 Y 轴值显示为字符串值,如“NA”。但我的数据返回正确的数据。但图表不可见。它仍在加载。

http://jsfiddle.net/3ajw61ze/2/

$(函数(){

// Create the chart
$('#container').highcharts({
    chart: {
        type: 'column'
    },
    title: {
        text: 'Basic drilldown'
    },
    xAxis: {
        type: 'category'
    },
    plotOptions: {
        series: {
            borderWidth: 1,
            dataLabels: {
                enabled: true,
            }
        }
    },
    series: [{
        id: 'toplevel',
        name: 'Ratio',
        data: [
            {name: 'Income', y: 'NA',color:'Green', drilldown: null},
            {name: 'Expenses',  y: 'NA',color:'Red', drilldown: null},
            {name: 'NetProfit', y: 'NA',color:'Orange', drilldown: null}
        ]
    }],
    drilldown: {
        series: null
    }
})

});

标签: highcharts

解决方案


Highcharts 要求xy值是数字。要解决您的问题,您可以使用category轴类型:

yAxis: {
    categories: ['NA']
},
series: [{
    ...,
    data: [{
            y: 0,
            ...
        },
        ...
    ]
}]

现场演示:http: //jsfiddle.net/BlackLabel/spu2gfwn/

API 参考: https ://api.highcharts.com/highcharts/yAxis.type


推荐阅读