在轴上设置最小值和最大值

Setting a min & max on the axis

我正在使用 anuglar-nvd3,但在 API 上找不到任何文档。我现在面临的问题是如何在 xAxis 和 yAxis 上设置最大值和最小值。

换句话说,无论数据如何,轴的最小值为-1,最大值为1。

笨蛋:http://plnkr.co/edit/LKt3UJe5PnJOf8uQEwxr?p=preview

代码:

var app = angular.module('plunker', ['nvd3']);

app.controller('MainCtrl', function($scope) {
 $scope.options = {
            chart: {
                type: 'scatterChart',
                height: 450,
                color: d3.scale.category10().range(),
                scatter: {
                    onlyCircles: false
                },
                showDistX: true,
                showDistY: true,
                tooltipContent: function(key) {
                    return '<h3>' + key + '</h3>';
                },
                duration: 350,
                xAxis: {
                    scale: [0,5],
                    axisLabel: 'X Axis',
                    tickFormat: function(d){
                        return d3.format('.02f')(d);
                    }
                },
                yAxis: {
                    axisLabel: 'Y Axis',
                    tickFormat: function(d){
                        return d3.format('.02f')(d);
                    },
                    axisLabelDistance: -5
                },
                zoom: {
                    //NOTE: All attributes below are optional
                    enabled: false,
                    scaleExtent: [1, 10],
                    useFixedDomain: false,
                    useNiceScale: false,
                    horizontalOff: false,
                    verticalOff: false,
                    unzoomEventType: 'dblclick.zoom'
                },
                margin: {
                  top: 100,
                  right: 100,
                  left: 100,
                  bottom: 100
                }
            }
        };

        $scope.data = [
        {
          "key":"static",
          "color":"#fff",
          "values":[
             {
                "x":-1,
                "y":-1,
                "size":0.0000001,
                "shape":"circle",
                "series":0
             },
             {
                "x":1,
                "y":1,
                "size":0.0000001,
                "shape":"circle",
                "series":0
             }
          ]
       },
       {
          "key":"Group 0",
          "color":"#1f77b4",
          "values":[
             {
                "x":-0.5,
                "y":-0.5,
                "size":0.5,
                "shape":"circle",
                "series":0
             }
          ]
       },
       {
          "key":"Group 1",
          "color":"#ff7f0e",
          "values":[
             {
                "x":-0.5,
                "y":0.5,
                "size":0.5,
                "shape":"circle",
                "series":0
             }
          ]
       },
       {
          "key":"Group 2",
          "color":"#2ca02c",
          "values":[
             {
                "x":0.5,
                "y":-0.5,
                "size":0.5,
                "shape":"circle",
                "series":0
             }
          ]
       },
       {
          "key":"Group 3",
          "color":"#d62728",
          "values":[
             {
                "x":0.5,
                "y":0.5,
                "size":0.5,
                "shape":"circle",
                "series":0
             }
          ]
       }
    ];

});

你试过了吗

forceY: [-1, 1],
forceX: [-1, 1],