maikelm maikelm -4 years ago 273
AngularJS Question

make zoom using nvd3

I need make zoom in graphic. I am using angular js and nvd3.
this is a part of my Code, html and angular module:



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

app.controller('daCtrl', function($scope) {

$scope.graphic = [{key: "a", values: [[243434, 1],[363352, 2],...]}, [[243434, 1],[363352, 2],...]},... ];

$scope.options = {
chart: {
type: "lineChart",
height: 450,
margin : {
top: 20,
right: 20,
bottom: 60,
left: 65
},
x: function(d){ return d[0]; },
y: function(d){ return d[1]/100; },
average: function(d) { return d.mean/100; },

color: d3.scale.category10().range(),
transitionDuration: 300,
useInteractiveGuideline: true,
clipVoronoi: false,

xAxis: {
axisLabel: 'Date',
tickFormat: function(d) {
return d3.time.format('%m/%d/%y')(new Date(d));
}
},

yAxis: {
axisLabel: 'Measure',
tickFormat: function(d){
return d3.format('.02f')(d);
},
axisLabelDistance: 20,
showMaxMin: true,
staggerLabels: true
}

}
};
});

<link rel="stylesheet" type="text/css" href="../bower_components/nvd3/nv.d3.css">

<script src="../bower_components/d3/d3.js"></script>
<script src="../bower_components/nvd3/nv.d3.js"></script>
<script src="../bower_components/angular-nvd3/dist/angular-nvd3.js"></script>

<nvd3 options="options" data="graphic"></nvd3>





The graphic is ok, but I need make zoom over the graphic.
I've seen that D3 is possible, but not if you can with equally nvd3

Answer Source

I changed nvd3 to dygraph using Dygraphs angularjs Directive (https://twittstrap.com/dygraphs-angularjs-directive/)

Now (the same example of website)

HTML:

<head>
    <script src="bower_components/jquery/dist/jquery.min.js"></script>
    <script src="bower_components/dygraphs/dygraph-combined.js"></script>
    <script src="bower_components/angular/angular.min.js"></script>
    <script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
    <script src="bower_components/moment/moment.js"></script>
    <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="bower_components/angular-dygraphs/src/angular-dygraphs.js"></script>

    <!--<link rel="stylesheet" type="text/css" href="bower_components/angular-dygraphs/demo/demo.css"/>-->
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
</head>
<body ng-app="demoApp">
<div ng-controller="DemoCtrl">
    <ng-dygraphs data="graph.data" options="graph.options"  legend="graph.legend"></ng-dygraphs>
<div>
</body>

js:

var example = angular.module('demoApp', [
        "angular-dygraphs"
    ]);

    demoApp.controller('DemoCtrl', function ($scope) {
        $scope.graph = {
            data: [
            ],
            options: {
                labels: ["x", "A", "B"]
            },
            legend: {
                series: {
                    A: {
                        label: "Series A"
                    },
                    B: {
                        label: "Series B",
                        format: 3
                    }
                }
            }
        };

        var base_time = Date.parse("2008/07/01");
        var num = 24 * 0.25 * 365;
        for (var i = 0; i < num; i++) {
            $scope.graph.data.push([ new Date(base_time + i * 3600 * 1000),
                i + 50 * (i % 60),        // line
                i * (num - i) * 4.0 / num  // parabola
            ]);
        }
       
    });

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download