首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有角的高图,去掉xAxis线

问带有角的高图,去掉xAxis线
EN

Stack Overflow用户
提问于 2014-10-24 06:56:37
回答 1查看 2.1K关注 0票数 0

我使用的是高级图表,我做了一个名为sparkLine的指令,这是它的代码:

代码语言:javascript
复制
chartModule.directive('sparkLine', function () {
return {
    restrict: 'E',
    scope: {
        series: '=',
        lineName: '=',
        lineTooltip: '=',
        xAxisEnabled: '=',
        yAxisEnabled: '=',
        lineColor: '='
    },
    replace: true,
    template: '<div></div>',

    link: function (scope, element, attrs) {

        var xEnable = (typeof (attrs.xAxisEnabled) == 'undefined') ? false : true;
        var yEnable = (typeof (attrs.yAxisEnabled) == 'undefined') ? false : true;
        var lColor = (typeof (attrs.lineColor) == 'undefined') ? '#808080' : lineColor;

        $(element).highcharts({
            chart:
            {
                type: 'line',
                width: attrs.width,
                height: attrs.height,
                backgroundColor: attrs.backgroundColor
            },
            title: {
                text: ''
            },
            plotOptions: {
                series: {
                    marker: {
                        radius: (typeof (attrs.pointRadius) == 'undefined') ? 2 : attrs.pointRadius,
                    }
                }
            },
            navigation: {
                buttonOptions: {
                    enabled: false
                }
            },
            credits: {
                enabled: false
            },

            xAxis: {
                lineColor: 'transparent',
                tickWidth: 0,
                lineHeight: 0,
                labels: {
                    enabled: xEnable
                },
                categories: []
            },
            yAxis: {
                lineColor: 'transparent',
                gridLineColor: 'trasparent',
                title: {
                    text: ''
                },
                labels: {
                    enabled: yEnable
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: lColor
                }]
            },
            tooltip: {
                formatter:
                    function () {
                        return scope.lineTooltip(this.x, scope.lineName, this.y.toLocaleString());
                    },
                hideDelay: 50
            },
            legend: {
                enabled: false
            },
            series: [{
                name: '',
                data: []
            }]
        });

        scope.$watch('series', function () {
            var chart = $(element).highcharts();
            scope.newperiodsTrends = [];
            scope.categoriesPeriods = [];
            angular.forEach(scope.series, function (elm, index) {
                scope.newperiodsTrends.push(elm.Value);
                scope.categoriesPeriods.push(elm.IterationName);
            });

            chart.series[0].setData(scope.newperiodsTrends);
            chart.xAxis[0].setCategories(scope.categoriesPeriods);
        });
    }
}

});

在我的代码中,这个指令的用法是:

代码语言:javascript
复制
 <spark-line series="dataSeries" line-tooltip="tooltip" line-name="'Value'" class="sparkLine">

在我的html代码中,我使用angularjs,并使用ng-重复创建了一个表:

​

​

我的问题是,我不能从其中一个图中删除xAxis。

编辑:我发现了一个问题:当我删除包含在css文件中的高度和宽度(class = "sparkLine")时,行被删除了,这可能是一个高图表故障.如果有解决办法的话,我很想听听。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-24 11:48:50

至于高级图表,您可以使用Axis.remove - API接口删除轴.

如果您希望将其隐藏在视图中,则在以下情况下,您将正确地执行此操作:

代码语言:javascript
复制
xAxis: {
   ...  
   lineWidth: 0,
   minorGridLineWidth: 0,
   lineColor: 'transparent',
   ...          
   labels: {
       enabled: false
   },
   minorTickLength: 0,
   tickLength: 0
}

来源

活生生的例子,如jsFiddle将非常有助于确定不需要的灰色线的起源。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26542939

复制
相关文章

相似问题

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