简体   繁体   English

试图在图表上绘制虚线

[英]trying to draw dotted lines over the chart

Hey Guys I'm trying to draw dotted lines over my highcharts chart but when I try this the lines either push the chart out of position or skip over the chart and continue past it.I'm also trying to put labels on the top of each barchart too 嗨,我正在尝试在高点图表上绘制虚线,但是当我尝试这样做时,这些线条要么将图表推到位,要么跳过图表并继续通过它。我还试图在标签上方放置标签每个条形图

here's my code 这是我的代码

$(function () {
        $('#container5').highcharts({
            chart: {
                type: 'column'

            },
            title: {
                text: ''
            },
            subtitle: {
                text: ''
            },
            tooltip: { enabled: false },
            exporting: {
                   enabled:false
                },

             credits: {
                  enabled: false
              },

              legend: {
                  enabled:false
              },
            xAxis: {
                 labels:
                    {
                      enabled: false
                    },
                    lineColor: 'transparent',
                     minorTickLength: 0,
                       tickLength: 0,
                       min: 0,
                          lineWidth: 0,
                   minorGridLineWidth: 0,
                   lineColor: 'transparent',

                      gridLineColor: 'transparent',
                        title: {
                            text: ''
                        },
                categories: ['']
            },
            yAxis: {
                 labels:
                    {
                      enabled: false
                    },
                    lineColor: 'transparent',
                     minorTickLength: 0,
                       tickLength: 0,
                       min: 0,
                          lineWidth: 0,
                   minorGridLineWidth: 0,
                   lineColor: 'transparent',


                      gridLineColor: 'transparent',
                        title: {
                            text: ''
                        },
                min: 0,
                title: {
                    text: ' '
                },

            },


            plotOptions: {
                column: {
                    stacking: 'normal',
                     animation: false

                },
                series: {
                    states: {
                        hover: {
                            enabled: false
                        }
                    }
                }
            },

            series: [{
                name: '10',
                data: [10],
                 pointWidth: 50,
                 groupPadding: 0,
                 color: '#f7a35c'
            }, {
                name: '12',
                data: [12],
                pointWidth: 50,
                groupPadding: 0,
                color: '#004A98'
            }, {
                name: '12',
                data: [12],
                pointWidth: 50,
                groupPadding: 0,
                color: '#509ADC'
            }]
        });
    });

and

<div class="col-md-2" id="container5" style="width: 200px; height: 700px; margin:auto"></div>

It looks like 看起来像

Picture one 图片一

but I want it to look like this 但我希望它看起来像这样

Picture two 图片二

Deffine your plot lines on YAxis like this. 像这样在YAxis上定义绘图线。 Demo 演示

yAxis: {
     title: {
         ...
     },
     plotLines: [{
         value: minValue,
         color: 'green',
         dashStyle: 'shortdash',
         width: 2,
         label: {
             text: 'Last quarter minimum'
         }
     }, {
         value: maxValue,
         color: 'red',
         dashStyle: 'shortdash',
         width: 2,
         label: {
             text: 'Last quarter maximum'
         }
     }]
 }

EDIT 编辑

In addition to, if you want to align the plotLines to the left you can try this: 另外,如果您想将plotLines对齐到左侧,则可以尝试以下操作:

Highcharts.Renderer.prototype.symbols.hline = function(x, y, width, height) {
    return ['M',x*2,y + height,'L',0,y + width];
};

DEMO DEMO

You can use Renderer.path to add custom line in the chart. 您可以使用Renderer.path在图表中添加自定义线。

chart.renderer.path(['M', 0, 0, 'L', 100, 100])
    .attr({
        'stroke-width': 2,
        stroke: 'red'
    })
    .add();

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

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