10

我正在使用 Highcharts,我想在值上绘制垂直线。喜欢;

在此处输入图像描述

我怎样才能做到这一点 ?谢谢。

这是我的代码

        <script type="text/javascript">

$(function () {
    var chart;
$(document).ready(function() {

    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container',
            type: 'area'
        },
    title: {
        text: '<b> </b>'
    },
        xAxis: {

            labels: {
                formatter: function() {
                    return this.value; // clean, unformatted number for year
                }
            }
        },
        yAxis: {
            labels: {
                formatter: function() {
                    return this.value / 1000 +'k';
                }
            }
        },
        tooltip: {
            formatter: function() {
                return '<b>'+ Highcharts.numberFormat(this.y, 0) +'</b>';
            }
        },
            xAxis: {
        categories: [
            'Mon',
            'Tue',
            'Wed',
            'Thu',
            'Fri',
            'Sat',
            'Sun'
        ],
        plotBands: [{ // visualize the weekend
            from: 5.5,
            to: 6.5,
            color: 'rgba(68, 170, 213, .2)'
        }]
    },

        plotOptions: {

            area: {
                pointStart: 1,
                marker: {
                    enabled: false,
                    symbol: 'circle',
                    radius: 1,
                    states: {
                        hover: {
                            enabled: true
                        }
                    }
                }
            }
        },
        series: [{
            name: 'Visit',
            data: [946, 733, 764, 887, 832,1423]
        }, {
            name: 'Unique',
            data: [746, 633, 664, 687,702,1266]
        }]
    });
});

});
    </script>
4

5 回答 5

10

您很可能必须使用Highcharts 渲染器来完成此任务,因为您想要做的事情不太适合网格,也不适合情节线。

我根据您的代码制作了一个非常简单的示例,该代码显示在硬编码位置绘制任意垂直线。为了实现您的目标,您必须计算一些东西,例如每条线的起点的 x/y 位置,以及基于该点值的线的高度。

这是一个稍微不同的示例,其中 zIndex 和您实际需要的一条线,使用Vpath 命令绘制一条垂直线。

于 2012-06-08T15:50:39.053 回答
5

我想你可能正在寻找情节带和/或情节线。

这里有一些更多信息:

http://www.highcharts.com/docs/chart-concepts/plot-bands-and-plot-lines

于 2014-07-09T04:15:54.207 回答
3

试试这个jsFiddle。来自Highcharts API

于 2012-06-08T14:59:16.583 回答
2

如果您只想要一条线(以及从该线开始的区域):

xAxis:{     
    plotLines: [{
        color: 'red', // Color value
        //dashStyle: 'solid', // Style of the plot line. Default to solid
        value: + new Date(), // Value of where the line will appear
        width: '2' // Width of the line    
    }],
    plotBands: [{
        color: '#FFFAFA', // Color value
        from:  +new Date(), // Start of the plot band
        to:    +new Date()+1000*24*3600*30, //30 days
    }],
}
于 2014-08-16T14:16:40.760 回答
0

解决方案是在类型中包含一个新系列,column并向该系列添加与包含该点的其他系列相同的数据。

{
    /* Column type */
    type: 'column',
    name: '',
    data: [],
    color: '#ED1C24',
    pointWidth: 2,
    showInLegend: false,
    states: { hover: { enabled: false } }
}

使用这个 JSFiddle 作为指南:http: //jsfiddle.net/NDpu6/

于 2020-11-23T13:51:14.803 回答