首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >删除图表上的网格线

删除图表上的网格线
EN

Stack Overflow用户
提问于 2012-12-22 19:13:36
回答 4查看 49K关注 0票数 21

我有lib HighCharts的charts,我想在图表上删除yAxis的网格线,我编写了gridLineWidth: 0,但网格线不会删除所有代码:

代码语言:javascript
复制
<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>
EN

回答 4

Stack Overflow用户

发布于 2015-03-05 22:38:59

如果您不想接触配置对象,只需通过css隐藏网格即可:

代码语言:javascript
复制
.chart-container .highcharts-grid {
   display: none;
}
票数 5
EN

Stack Overflow用户

发布于 2017-02-01 14:54:46

代码语言:javascript
复制
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
}
票数 2
EN

Stack Overflow用户

发布于 2018-09-21 08:06:15

上面提到的解决方案对我来说都不起作用,所以这个方案终于起作用了(摘自Sparkline示例:https://www.highcharts.com/demo/sparkline):

代码语言:javascript
复制
yAxis: {
    startOnTick: false,
    endOnTick: false,
    tickPositions: [],
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14002342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档