Changing the y-axis scale in nvd3

守給你的承諾、 提交于 2019-12-08 07:23:10

问题


I am very new to nvd3. I plot a line chart, where most of the points are in the the Y-axis range 99 to 101. Only a few value will be outside this range. Check this image:

I want this range to be enlarged all the time. I want end users to focus on the range from 99 to 101, regardless of a big or small values as outliers. Basically, the focus should be on the range from 99 to 101, but the other datapoints should also be displayed.

This is my current code:

$scope.setChartType = function(type) {
      console.log(type);
      $scope.options.chart.type = type;
    };
    $scope.options = {
      chart: {
        type: 'lineChart',
        height: ClickHandlerService.chartOptions.height,
        margin: ClickHandlerService.chartOptions.margin,
        x: function (d) {
          return parseInt(d.timestamp);
        },
        y: function (d) {
          return d.latency;
        },
        useInteractiveGuideline: true,
        staggerLabels: true,
        stacked: false,

        transitionDuration: ClickHandlerService.chartOptions.transitionDuration,
        transitionEase: ClickHandlerService.chartOptions.transitionEase,
        dispatch: {
          stateChange: function (e) { /*Placeholder for graph events*/
          },
          changeState: function (e) { /*Placeholder for graph events*/
          },
          tooltipShow: function (e) { /*Placeholder for graph events*/
          },
          tooltipHide: function (e) { /*Placeholder for graph events*/
          }
        },
        xAxis: {
          tickFormat: function (d) {
            return moment(d * 1000).utcOffset(-8).add(1, 'hours').format('DD-MM-YYYY/HH');
          },
          showMaxMin: false
        },
        yAxis: {
          axisLabel: 'Data Latency (In minutes)',
          tickFormat: function (d) {
            return d3.format('.02f')(d);
          },
          axisLabelDistance: 30,
          showMaxMin: false
        },
        callback: function (chart) {
        }
      },
      title: {
        enable: true,
        text: graphDetails.name
      },
      caption: {
        enable: true,
        html: ClickHandlerService.chartOptions.dataLatencyCaption,
        css: ClickHandlerService.chartOptions.captionCss
      }
    }; 

回答1:


You can set chart.yDomain to [99-101] (or whatever range you want).

Here is an example.



来源:https://stackoverflow.com/questions/30112788/changing-the-y-axis-scale-in-nvd3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!