Highchart: Background color of Axis

后端 未结 2 335
野的像风
野的像风 2020-12-21 10:11

I saw a similar question here.

In reply its written that we can have background color by making a rectangle.

My question is how I can get x and

相关标签:
2条回答
  • 2020-12-21 10:56

    Here's a quick example that shades between the 2nd and 4th ticks:

    var tickStart = 1;
    var tickEnd = 3;
    
    $(function () {
    
       var rect = null;
       function drawRect(chart){
           if (rect){
               rect.element.remove();   
           }        
    
            var xAxis = chart.xAxis[0];  
            var pixStart = xAxis.toPixels (xAxis.tickPositions[tickStart], false);
            var pixEnd = xAxis.toPixels (xAxis.tickPositions[tickEnd], false);
            rect = chart.renderer.rect(pixStart, chart.chartHeight - xAxis.bottom, pixEnd - pixStart , 25, 00)
            .attr({
               'stroke-width': 0,
               stroke: '#888888',
               fill: '#888888',
               zIndex: 3
            })
            .add();
        }
    
        $('#container').highcharts({
            chart: {
                events: {
                    load: function() {
                        drawRect(this);
                    },
                    redraw: function(){
                        drawRect(this);
                    }
                }        
            },
            xAxis: {
            },
    
            series: [{
                animation: false,
                data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]     
            }]
        });
    });
    

    Fiddle here.

    enter image description here

    0 讨论(0)
  • 2020-12-21 11:07

    Did you try to use labels.formatter with background and useHTML flag? Something like this: http://jsfiddle.net/AeV7h/

        xAxis: {
            categories: ['Foo', 'Bar', 'Foobar'],
    
            labels: {
                useHTML: true,
                formatter: function() {
                    return '<span class="hc-label">' + this.value + '</span>';
                }
            }
        },
    

    And CSS:

    .hc-label {
      background-color: red;
      padding: 0px 5px;
      color: yellow;
    }
    
    0 讨论(0)
提交回复
热议问题