Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove grid line on chart

I have the charts of lib HighCharts and I want to remove the gridline of yAxis on charts I write gridLineWidth: 0 but gridlines are not removing All code:

<script type="text/javascript">
(function($){ // encapsulate jQuery

$(function() {
    Highcharts.setOptions({
        lang: {
            rangeSelectorZoom: 'Маcштаб',
            rangeSelectorFrom: 'От',
            rangeSelectorTo: 'До',
            thousandsSep: ' '
        },
        global: {
            useUTC: false
        }
    });

    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) {
        // Create the chart
        window.chart = new Highcharts.StockChart({
            chart : {
                borderColor: 'white',
                renderTo : <?php echo "cont".$i; ?>,
                backgroundColor: '#f9f9f9' // Сделаем слегка серый фон
            },

            rangeSelector: {
                buttons: [  
                { 
                    type: 'week', 
                    count: 1, 
                    text: 'Неделя',
                },  
                { 
                    type: 'month', 
                    count: 1, 
                    text: 'Месяц',
                },              
                { 
                    type: 'year', 
                    count: 1, 
                    text: 'Год'
                },
                {
                    type: 'all',
                    text: 'Всё'
                }],
                inputDateFormat: '%d.%m.%Y', // Меняем на привычный для нас формат даты в интервалах
                inputEditDateFormat: '%d.%m.%Y',
                buttonTheme: {
                    width: 43 // Увеличим ширину кнопки
                },
                selected: 1 // Какая кнопка выбрана по умолчанию
            },

            yAxis: [{
            gridLineWidth: 0,
            plotBands: [{ 
                 color: 'rgba(1, 143, 189, 1)',
                 from: -2,
                 to: 11
             },
             { 
                 color: 'rgba(157, 200, 5, 1)',
                 from: 11,
                 to: 21
             },
             { 
                 color: 'rgba(202, 1, 94, 1)',
                 from: 21,
                 to: 50
             }],


                title: {
                    text: 'Позиции'
                },
                startOnTick: false,
             //   min: 1,
                showFirstLabel: true,
                showLastLabel: true,
                reversed: true,
                tickPositioner: function(min, max) {
                    // specify an interval for ticks or use max and min to get the interval
                    var interval = Math.round((max-min)/5);
                    // push the min value at beginning of array
                    var dataMin=this.dataMin;
                    var dataMax=this.dataMax;          
                    var positions = [dataMin];
                    var defaultPositions = this.getLinearTickPositions(interval, dataMin, max);
                    //push all other values that fall between min and max
                    for (var i = 0; i < defaultPositions.length; i++) {
                        if (defaultPositions[i] > dataMin && defaultPositions[i] < dataMax) {
                            positions.push(defaultPositions[i]);
                        }
                    }
                    // push the max value at the end of the array
                    positions.push(dataMax);
                    return positions;
                },
                //changed min valuereversed: true
            }],
            navigator: {
                enabled: false,
                maskFill: 'rgba(255, 255, 255, 0.45)',
                //margin: 20,
                series: {
                    type: 'areaspline',
                    color: 'rgba(255, 255, 255, 0.00)',
                    fillOpacity: 0.4,
                    dataGrouping: {
                        smoothed: false
                    },
                    lineWidth: 2,
                    lineColor: '#e9cc00',
                    marker: {
                        enabled: false
                    },
                    shadow: true
                },
                yAxis: {
                    reversed: true
                }
            },
            xAxis : { 
                gridLineWidth: 0,
                type: 'datetime',
                title : {
                    text : ' '
                },
            },

            title : {
                //text : 'Позиции сайта'
            },
            legend: {
                enabled: true,
                align: 'center',
                itemWidth: 234, // указал ширину, чтобы выводились сайты в 4 колонки
                verticalAlign: 'top'
            },          
            series : [{
                lineColor: 'white',
                name : 'Позиция в яндексе',
                id : 'dataseries',
                data : <?php echo $d ?>,
                tooltip: {
                    backgroundColor: 'rgba(250, 250, 250, .85)', // Фон немного темнее
                    borderColor: 'rgba(100, 100, 100, .90)', // Цвет границы (по умолчанию меняется автоматом)
                    xDateFormat: '%d.%m.%Y %H:%M', // Наш формат даты
                    // Тут немного увеличиваем размер даты
                    headerFormat: '<span style="font-size: 12px">{point.key}</span><br/>',
                    // Формат надписей в подсказке, названия цветом графика, а значения жирным
                    pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b><br/>',
                    //valueDecimals: 2
                }
            }]
        });
    });

});

})(jQuery);
</script>
like image 314
Ilya Z. Avatar asked Dec 22 '12 11:12

Ilya Z.


4 Answers

The problem is not the gridLineWidth. You've set that correctly.

In addition you need to set the minorGridLineWidth that you have to set to 0

Working demo

like image 69
Horen Avatar answered Oct 28 '22 19:10

Horen


If you doesn't want to touch the config object, you just hide the grid by css:

.chart-container .highcharts-grid {
   display: none;
}
like image 35
Iran Reyes Avatar answered Oct 28 '22 18:10

Iran Reyes


you just need to gridLineWidth set to 0
yAxis: {
           min:0,
           categories: ["","Low","Medium","High"],
           tickWidth: 0,
           crosshair: false,
           lineWidth: 0,
           gridLineWidth:0,//Set this to zero
           title: '',
           labels: {
                       formatter: function () {
                           return this.value;labels
                           }            
                       },
                       showEmpty: false
}
like image 2
alfishan aqeel Avatar answered Oct 28 '22 17:10

alfishan aqeel


None of the mentioned solutions worked for me, so this one finally worked (taken from Sparklines examples: https://www.highcharts.com/demo/sparkline):

yAxis: {
    startOnTick: false,
    endOnTick: false,
    tickPositions: [],
}
like image 2
darklow Avatar answered Oct 28 '22 19:10

darklow