简体   繁体   English

Highcharts:如何突出显示yAxis值?

[英]Highcharts: how to highlight yAxis value?

I am trying to give highcharts yAxis values a simple highlight to at certain points. 我试图在某些时候为高图表yAxis值提供一个简单的突出显示。 I have a value range that goes to 1 to 50, but I need to highlight 1, 30 and 50. 我的取值范围是1到50,但是我需要突出显示1、30和50。

Is there a way to do that? 有没有办法做到这一点? (green) (绿色)

my chart is bar right now but it could be column, I don`t mind 我的图表现在是柱状,但可能是柱状,我不介意

在此处输入图片说明

  var cidades = ["São Paulo", "Rio de Janeiro", "Belo Horizonte", "Curitiba", "Salvador", "Fortaleza", "Florianópolis"] var valoresCidades = [45, 35, 25, 15, 10, 5, 2]; $('#chartCidades').highcharts({ chart: { type: 'bar' }, title: { text: 'Pedidos por região' }, xAxis: { categories: cidades }, yAxis: { min: 0, max: 50, title: { text: 'Número de pedidos' }, plotLines: [{ value: 50, color: 'green', dashStyle: 'shortdash', width: 2, }, { value: 30, color: 'grey', dashStyle: 'shortdash', width: 2, }], stackLabels: { enabled: true, style: { fontSize: '10', fontWeight: 'lighter', color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray' } } }, legend: { align: 'left', x: -30, verticalAlign: 'top', y: 25, floating: true, backgroundColor: (Highcharts.theme && Highcharts.theme.background2) || 'white', borderColor: '#CCC', borderWidth: 1, shadow: false }, tooltip: { headerFormat: '<b>{point.x}</b><br/>', pointFormat: '{series.name}: {point.y:,.0f}<br/>' }, legend: { y: 30, verticalAlign: "top", align: "center", }, plotOptions: { column: { dataLabels: { enabled: false, color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white', style: { fontSize: '9', textShadow: '0 0 1px black' } } } }, colors: [ '#FF5722', '#607D8B' ], series: [{ name: 'Pedidos', data: valoresCidades }] }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="http://code.highcharts.com/highcharts-more.js"></script> <script src="http://code.highcharts.com/maps/modules/map.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <div id="chartCidades"></div> 

You can add plotLines or even areas to the chart to achieve that effect. 您可以在图表上添加plotLines甚至面积,以实现该效果。 (one or many). (一个或多个)。 You can use addPlotLine to any axis. 您可以对任何轴使用addPlotLine。

http://jsfiddle.net/aev2u0a4/ http://jsfiddle.net/aev2u0a4/

 chart.yAxis[0].addPlotLine({
                value: 500,
                color: 'red',
                width: 2,
                id: 'plot-line-1'
            });

Here is a sample based on highcharts own demo. 这是一个基于highcharts自己的演示的示例。 Click the button to see the line added/removed. 单击按钮查看添加/删除的行。

hc API doc HC API文档

It happens that you can add plotLines to the yAxis initialization options, like this: 碰巧您可以将plotLines添加到yAxis初始化选项,如下所示:

                    plotLines: [{
                        value: 50,
                        color: 'green',
                        dashStyle: 'shortdash',
                        width: 2,
                    }, {
                        value: 30,
                        color: 'grey',
                        dashStyle: 'shortdash',
                        width: 2,
                    }],

This basically solved my problem. 这基本上解决了我的问题。 I have updated my original snippet. 我已经更新了我的原始代码段。

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

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