首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何隐藏n3图表中第一个孩子和最后一个孩子的刻度

如何隐藏n3图表中第一个孩子和最后一个孩子的刻度
EN

Stack Overflow用户
提问于 2015-05-13 22:41:37
回答 1查看 516关注 0票数 0

我使用n3-charts,它使用line-chart.min.js和d3.v2.js插件。我想隐藏x轴,第0个滴答值和最后一个子滴答值。下图中的操作方法。

好心的,有人帮我解决这个问题,我不想要的APR11和最后一个滴答值,这将动态变化。

代码语言:javascript
复制
app.directive('barChart', [
                       function () {

                           return {
                               restrict: 'EA',
                               template: '<linechart data="data" options="options" width="550" height="291"></linechart>',
                               scope: {
                                   range: '=',
                               },
                               link: function(scope, elements, attrs){
                                   scope.$watch("range", function () { 
                                   var values = scope.range;
                                   scope.data = values;
                                       scope.options = {
                                           yaxis  : {name: "Calories",labelalign:"-135"},
                                           stacks: [{axis: "y", series: ["firstVal", "secondVal", 'thirdVal']}],
                                           fonts:  {family: 'serif', size: '14px'},
                                           axes: {
                                               x: {key: 'x', type: 'date',labelFunction: function(x) { return d3.time.format('%b %d')(new Date(x));}},
                                               y: {key :'y',type: 'linear',min:0}
                                           },
                                           transition: {ease: 'elastic', duration: 1000, delay: 100},
                                           series: [
                                               {id: 'secondVal', y: 'secondVal', axis: 'y', color: "#b3d660", type: 'column', drawDots: true, dotSize: 4, label: 'Labe1'},
                                               {id: 'firstVal', y: 'firstVal', axis: 'y', color: "#ff8669", thickness: '2px', type: 'column', label: 'Label2'},
                                               {id: 'thirdVal', y: 'thirdVal', axis: 'y', color: "#52c4dc", type: 'column', dotSize: 2, label: 'Label3'}
                                           ],
                                           lineMode: 'linear',
                                           tension: 0.2,
                                           tooltip: {
                                               mode: 'scrubber', formatter: function (x, y, series) {
                                                   return series.label + ', ' + Math.round(y);
                                               }
                                           },
                                           drawLegend: true,
                                           drawDots: true,
                                           columnsHGap: 5
                                       }
                                   });
                               }

                           };}]);
EN

回答 1

Stack Overflow用户

发布于 2016-02-26 17:20:21

对于n3- v2,您可以为每个轴定义一个tickFormat函数。

将一个名为tickFormat的函数添加到called e.options.axes.x,如下所示:

代码语言:javascript
复制
tickFormat: function(value, index){
    var firstOrLast = (index === 0) || (index === scope.values.length-1);
    return firstOrLast ? "" : value;
}

不确定n3-charts的作用域,但我看到在v1中已经有一个名为labelFunction的函数。你可以做一些类似上面代码的事情,但是你只需要检查你的参数'x‘是否匹配你在scope.values中的第一个或最后一个值。

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

https://stackoverflow.com/questions/30218176

复制
相关文章

相似问题

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