简体   繁体   English

Highcharts x 范围系列:难以去除 y 轴上的数字标签

[英]Highcharts x-range series: difficulty removing numerical labels on y-axis

This is a question for anyone with HighchartsJS experience这是任何有 HighchartsJS 经验的人的问题

I'm currently having an issue displaying state data using the Highcharts X-range series charts.我目前在使用 Highcharts X 范围系列图表显示 state 数据时遇到问题。 Specifically, My problem is that our data that we are using to represent each individual state are both fairly high and non consecutive (768, 769 and 773).具体来说,我的问题是我们用来表示每个 state 的数据都相当高且不连续(768、769 和 773)。 To label these individual states I'm using a sparse array and placing my labels at the corresponding indices.对于 label 这些单独的状态,我使用稀疏数组并将标签放在相应的索引处。

The problem I am trying to solve which is depicted by this jsfiddle: https://jsfiddle.net/sn4d2hvq/10/这个jsfiddle描述的我试图解决的问题: https://jsfiddle.net/sn4d2hvq/10/

let categoryArray = [];
categoryArray[768] = 'one';
categoryArray[769] = 'two';
categoryArray[773] = 'three';


Highcharts.chart('container', {
    chart: {
        type: 'xrange'
    },
    title: {
        text: 'Example'
    },
    xAxis: {
        type: 'datetime'
    },
    yAxis: {
        title: {
            text: ''
        },
        categories: categoryArray,
    },
    series: [{
        name: 'dataset 1',
        borderColor: 'gray',
        pointWidth: 20,
        data: [{
            x: Date.UTC(2014, 10, 21),
            x2: Date.UTC(2014, 11, 2),
            y: 768,
        }, {
            x: Date.UTC(2014, 11, 2),
            x2: Date.UTC(2014, 11, 5),
            y: 769
        }, {
            x: Date.UTC(2014, 11, 8),
            x2: Date.UTC(2014, 11, 9),
            y: 773
        }, {
            x: Date.UTC(2014, 11, 9),
            x2: Date.UTC(2014, 11, 19),
            y: 769
        }, {
            x: Date.UTC(2014, 11, 10),
            x2: Date.UTC(2014, 11, 23),
            y: 773
        }],
        dataLabels: {
            enabled: true
        }
    }]

});

is that I want to exclude all values (which in this case means all numerical values) on the y-axis such that there are no numbers from zero up until the first index as well as no numbers in between any of the labels (ie. 770, 771,772).是我想排除 y 轴上的所有值(在这种情况下表示所有数值),这样从零到第一个索引都没有数字,也没有任何标签之间的数字(即。 770、771,772)。 Here's an example of the desired view: https://jsfiddle.net/estgbr6j/2/这是所需视图的示例: https://jsfiddle.net/estgbr6j/2/

let categoryArray = ['one', 'two', 'three'];


Highcharts.chart('container', {
    chart: {
        type: 'xrange'
    },
    title: {
        text: 'Example'
    },
    xAxis: {
        type: 'datetime'
    },
    yAxis: {
        title: {
            text: ''
        },
        categories: categoryArray,
    },
    plotOptions: {
      xrange: {
        colorByPoint: false,
      }
    },
    series: [{
        name: 'dataset 1',
        borderColor: 'gray',
        pointWidth: 20,
        data: [{
            x: Date.UTC(2014, 10, 21),
            x2: Date.UTC(2014, 11, 2),
            y: 0,
        }, {
            x: Date.UTC(2014, 11, 2),
            x2: Date.UTC(2014, 11, 5),
            y: 1
        }, {
            x: Date.UTC(2014, 11, 8),
            x2: Date.UTC(2014, 11, 9),
            y: 2
        }, {
            x: Date.UTC(2014, 11, 9),
            x2: Date.UTC(2014, 11, 19),
            y: 1
        }, {
            x: Date.UTC(2014, 11, 10),
            x2: Date.UTC(2014, 11, 23),
            y: 2
        }],
        dataLabels: {
            enabled: true
        }
    }]

});

The only way I've been able to consistently achieve the desired result (as depicted by the second example) has been to map the values from [768, 769, 773] => [0, 1, 2] and use a dense array to label the newly mapped values.我能够始终如一地达到预期结果(如第二个示例所示)的唯一方法是 map 的值来自 [768, 769, 773] => [0, 1, 2] 并使用密集数组到 label 新映射的值。 It seems that this workaround shouldn't be necessary but I have yet to find an option in the highcharts API to easily allow for our desired result without mapping the values.似乎不需要这种解决方法,但我还没有在 highcharts API 中找到一个选项,以便在不映射值的情况下轻松实现我们想要的结果。 It should also be noted that in our actual data set, we are usually displaying multiple series with each series depicted by its own color rather than each category (which I have been able to achieve).还应该注意的是,在我们的实际数据集中,我们通常显示多个系列,每个系列都用自己的颜色而不是每个类别来表示(我已经能够实现)。 I would like to know which API option or options are available to display our desired result.我想知道可以使用哪个 API 选项或选项来显示我们想要的结果。 Thank you so much.太感谢了。

highcharts: 9.0.1 highcharts-angular: 2.10.0 angular: 12.0.5 node: 14.18.0 highcharts:9.0.1 高角:2.10.0 angular:12.0.5 节点:14.18.0

The solution with mapping your data is really good.映射数据的解决方案非常好。 The intervals must be regular if you want to have equally distributed points.如果您想要平均分布的点,则间隔必须是规则的。

data: [{
    x: Date.UTC(2014, 10, 21),
    x2: Date.UTC(2014, 11, 2),
    y: 0,
}, {
    x: Date.UTC(2014, 11, 2),
    x2: Date.UTC(2014, 11, 5),
    y: 1
}, {
    x: Date.UTC(2014, 11, 8),
    x2: Date.UTC(2014, 11, 9),
    y: 2
}, {
    x: Date.UTC(2014, 11, 9),
    x2: Date.UTC(2014, 11, 19),
    y: 1
}, {
    x: Date.UTC(2014, 11, 10),
    x2: Date.UTC(2014, 11, 23),
    y: 2
}]

You can use tickPositions property, but labels will not be equally distributed.您可以使用tickPositions属性,但标签不会平均分布。 Example: https://jsfiddle.net/BlackLabel/gbwhk5nx/示例: https://jsfiddle.net/BlackLabel/gbwhk5nx/


API Reference: https://api.highcharts.com/highcharts/yAxis.tickPositions API 参考: https://api.highcharts.com/highcharts/yAxis.tickPositions

mateusz.b on the official Highcharts forum had a great answer to this.官方 Highcharts 论坛上的 mateusz.b 对此有很好的回答。 He suggested using a columnrange series instead of an xrange series to present the data.他建议使用 columnrange 系列而不是 xrange 系列来呈现数据。

Check out the post here: https://www.highcharts.com/forum/viewtopic.php?f=9&t=47822在这里查看帖子: https://www.highcharts.com/forum/viewtopic.php?f=9&t=47822

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM