javascript - 仅存在一个值时如何显示绘图线

标签 javascript highcharts

我在向下钻取折线图中显示绘图线时遇到问题。

一切工作正常,但当我深入研究 2015 年时(每行只有 1 个值),情节线不会显示。

我在 this post 中读到过有关此问题的信息但所有解决方案都 Not Acceptable ,因为它们禁用 yAxis 上的自动缩放。

这是发生的事情:

正常图表(向下钻取之前)。它运行完美:

The normal chart (before drill down)

该图表对 2014 年进行了深入分析(每行有 4 个值)。它运行完美:

The chart with a drill down on 2014 (Where I have 4 values per line)

对 2015 年进行深入分析的图表(每行有 1 个值)。绘图线不显示,并且两点位于同一位置:

The chart with a drill down on 2015(Where I have 1 value per line)

这是我初始化图表的方法:

/*Initialisation du chart*/
            chart = new Highcharts.Chart({
                chart: {
                    renderTo: instanceData.id,
                    type: 'line',
                    alignTicks: false
                },
                title: {
                    text: titre_drill
                },
                subtitle: {
                    text: soustitre_drill
                },
                legend:{
                    enabled:true
                },
                xAxis: {
                    type: 'category'
                },
                yAxis: [{
                    title: {
                        text: texte_ordonee_expedie,
                        style: {
                            color: color_expedie
                        }
                    },
                    plotLines : [{
                        value : seuil_expedie,
                        color : color_expedie,
                        dashStyle : 'shortdash',
                        width : 2,
                        label : {
                            text : ''
                        }
                    }],
                    labels: {
                        format: '{value} €',
                        style: {
                            color: color_expedie
                        }
                    },
                    gridLineColor: 'transparent'
                },
                {
                    title: {
                        text: texte_ordonee_packee,
                        style: {
                            color: color_packee
                        }
                    },
                    plotLines : [{
                        value : seuil_packee,
                        color : color_packee,
                        dashStyle : 'shortdash',
                        width : 2,
                        label : {
                            text : ''
                        }
                    }],
                    labels: {
                        format: '{value} €',
                        style: {
                            color: color_packee
                        }
                    },
                    gridLineColor: 'transparent',
                    opposite: true //Pour que le deuxième axe soit à l'opposé du premier
                }],
                plotOptions: {
                    line: {
                        cursor: 'pointer',
                        marker: {
                            symbol: 'triangle'
                        },
                        dataLabels: {
                            enabled: false
                        }
                    }
                },
                tooltip: {
                    formatter: function() {
                        return '<b>'+ this.y +'</b> €<br/>';
                    }
                },              
                series: main_data,
                drilldown: {
                    series: drilldown_series,
                    drillUpButton: {
                        relativeTo: 'spacingBox',
                        position: {
                            y: 0,
                            x: 0
                        }
                    }
                },
                exporting: {
                    enabled: true
                }
            });

我知道 Highcharts 中没有任何 native 函数可以“始终显示”绘图线。有没有人有建议,以便我可以在 2015 年的深入分析中显示我的两条情节线?

最佳答案

如果您想在自动缩放不会显示的点上显示情节线...您必须中断自动缩放。没有办法用情节线来解决这个问题。

要使用自动轴缩放,您可以做的是使用线系列而不是绘图线。
如果您希望它表现得像情节线而不是系列,您可以禁用图例条目、工具提示等。

这样,轴将始终自动缩放以包含您的线条。

示例:

关于javascript - 仅存在一个值时如何显示绘图线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936331/

相关文章:

javascript - jQuery DataTable fnDestroy 重新格式化表

javascript - 缩放 X 时 Highcharts 为空

javascript - 使用向下钻取系列更改图表类型

Javascript Object.defineProperty 在 FireFox 19.02 (MacOS) 中产生类型错误

javascript - 动画下划线链接有 3 种不同的颜色

javascript - 单击按钮后不显示按钮

javascript - 数据随 Highcharts point.update 变化

javascript - 如何在javascript中动态添加项目到数组

javascript - highchart 和 .clone() 的问题

javascript - Google Web 字体在 OSX Safari 中不显示,但在 Firefox、Chrome、Opera(适用于 OSX、Windows 和 Linux)和 Internet Explorer 中显示