Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.16.0/moment.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.17/d3.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.js"></script>
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.4/nv.d3.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/nvd3/1.8.4/nv.d3.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-nvd3/1.0.9/angular-nvd3.min.js"></script>  
 
  </head>
  <body>
    <div ng-app="nvd3_timeseries">
      <div ng-controller="demo">
        <nvd3 options="options" data="data"></nvd3>
      </div>
      <div><a href="https://twitter.com/intent/tweet?screen_name=cagomez805" class="twitter-mention-button" data-show-count="false">Tweet to @cagomez805</a><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></div>
    </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                // 1) Declare app
var nvd3_timeseries = angular.module('nvd3_timeseries', ['nvd3']);

// 2) Declare controller
nvd3_timeseries.controller('demo', ['$scope', function($scope) {
  // 3) Chart configuration
  $scope.options = {
    chart: {
      type: 'lineChart',
      height: 450,
      margin: {
        top: 20,
        right: 20,
        bottom: 40,
        left: 55
      },
      x: function(d) {
        /* Moment.js will attempt to parse the x coordinate 
                and return a value in milliseconds
                */
        return moment.utc(d.x).valueOf();
      },
      y: function(d) {
        return d.y;
      },
      useInteractiveGuideline: true,
      xAxis: {
        axisLabel: 'Date',
        tickFormat: (function(d) {
          // 3.1) Format the x ticks
          return d3.time.format('%-m/%-d/%-Y')(new Date(d));
        })
      },
      yAxis: {
        axisLabel: 'Cats',
        axisLabelDistance: -10
      },
      callback: function(chart) {}
    },
    title: {
      enable: true,
      text: 'Time Series graph'
    }
  };
  $scope.dateRange = function dateRange(startDate, endDate) {
    // http://stackoverflow.com/a/23796069
    var dates = [];
    var currDate = startDate.clone().startOf('day');
    var lastDate = endDate.clone().startOf('day');
    while (currDate.add(1, 'days').diff(lastDate) <= 0) {
      dates.push(currDate.clone().toDate());
    }
    return dates;
  };
  // 4) Chart data
  $scope.data = generateTimeSeries();
  function generateTimeSeries() {
    // Generate an array of dates for plotting
    var dateRange = $scope.dateRange(moment().subtract(7, 'days'), moment());
    // Plottable will be an array of (x, y) objects
    var plottable = dateRange;
    plottable.forEach(function to_utc(date, index) {
      console.log('a[' + index + '] = ' + date);
      // set x value to date and y to a random value
      var rand = Math.round((Math.random() * (100 - 1) + 1));
      var point = {
        x: date,
        y: rand
      };
      // Replace original element
      plottable[index] = point;
    });
    // Return the plottable array for plotting
    return [{
      values: plottable,
      key: 'Cats',
      color: '#1b75ba'
    }];
  };
}]);
              
            
!
999px

Console