cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Looking for quick-add? Try the external resource search, it's quicker and gives you access to the most recent version of thousands of libraries. ☝️

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

            
              <div ng-app="App" ng-controller="ctrl" ng-cloak="" layout="row" class="sbapp">
  <div flex></div>
  <div flex="90" md-whiteframe="5">
    <md-toolbar layout-padding layout="row" layout-xs="column" md-whiteframe="5" class="md-hue-2"> <b>DOW 30</b>  
    </md-toolbar>
    <div layout-padding layout="row" md-colors="::{background: 'default-primary-600-1'}" class ="md-toolbar-tools">
<!--       -tall -->
<!--             <span flex></span> -->
      <span layout ="row" layout-xs="column" class="md-subhead"><md-switch class="md-primary md-hue-3" ng-model="tVolume" ng-change="showVolume()">Traded Volume </md-switch></span>
      
      <span flex></span>
      <md-radio-group ng-model="range" layout="row" layout-xs="column" class="md-subhead" ng-change="rangeChange()">
        <b>Range: &nbsp;&nbsp;</b>
        <md-radio-button value="1" aria-label="YTD" class="md-primary md-hue-3">
          YTD
        </md-radio-button>
        <md-radio-button value="2" aria-label="12 Months" class="md-primary md-hue-3">
          12 Months
        </md-radio-button>
        <md-radio-button value="3" aria-label="30 Days" class="md-primary md-hue-3">
          30 Days
        </md-radio-button>
      </md-radio-group>
    </div>
    <md-content class="md-padding">
      <md-autocomplete md-selected-item-change="goFetch(item.stockSymbol)" md-match-case-insensitive="true" md-min-length="0" md-search-text="searchText" md-items="item in items | filter:searchText" md-item-text="item.companyName + space + item.stockSymbol"
        placeholder="Type Company Name or Stock Symbol">
        <span md-highlight-text="searchText">{{ item.companyName }} {{ item.stockSymbol }}</span>
      </md-autocomplete>
    </md-content>
    <md-content flex>

      <div layout="row" layout-align="center" layout-padding>
        <md-progress-circular ng-show="loadingStock" ng-disabled="indeterminate" class="md-hue-2" md-diameter="60px">
      </div>
      <div class="chartContainer">
        <canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels" chart-options="options" chart-dataset-override="datasetOverride" chart-click="onClick">
   </canvas>
      </div>
    </md-content>
  </div>

  <div flex></div>
</div>
            
          
!
            
              @media (max-width: 618px) {
  .md-toolbar-tools {
      min-height:110px !important;
  }
}

body,
html {
  background-color: #222;
}

.sbapp {
  padding-top: 20px;
}


.chartContainer{
  padding: 10px;
}

.md-subhead{
  font-size: 15px;
}

span.flex.blue{
  font-size: 20px;
  background-color: blue;
}
            
          
!
            
              // Currently out of order, Yahoo changed their API, so this needs to be updated.

//A material design Stock Chart browser made with angular, angular material and chart.js Data courtesy of Yahoo's API.

var app = angular.module('App', ["chart.js", "ngMaterial"]);

app.config(function($mdThemingProvider) {
  $mdThemingProvider.theme('default')
    .dark()
    .primaryPalette('purple');
});

app.controller('ctrl', ['$scope', function($scope) {
  $scope.items = stocks.DowJones30;
  $scope.searchText = '';
  $scope.space = " ";
  $scope.loadingStock = false;
  $scope.labels = [];
  $scope.data = [];
  $scope.tVolume = false;
  // Dates :  
  $scope.today = moment().format("YYYY-MM-DD");
  $scope.yearAgo = moment().subtract(1, 'year').format("YYYY-MM-DD");
  $scope.monthAgo = moment().subtract(1, 'month').format("YYYY-MM-DD");
  $scope.currentYearStart = moment().startOf('year').format('YYYY-MM-DD');
  $scope.currentYearEnd = moment().endOf('year').format('YYYY-MM-DD');
  $scope.range = "3";
  $scope.start = $scope.monthAgo;
  $scope.end = $scope.today;
  //Util vars
  var labels = [];
  var data = [];
  var volume = [];
  var ticker = '';

  $scope.showVolume = function() {
    if ($scope.tVolume) {
      $scope.options.scales.yAxes[1].display = true;
      $scope.datasetOverride[1].showLine = true;
      $scope.datasetOverride[1].hidden = false;
    } else {
      $scope.options.scales.yAxes[1].display = false;
      $scope.datasetOverride[1].showLine = false;
      $scope.datasetOverride[1].hidden = true;
    }
  };

  $scope.rangeChange = function() {
    switch ($scope.range) {
      case "1": // YTD
        $scope.start = $scope.currentYearStart;
        $scope.end = $scope.today;
        break;
      case "2": //12 Months
        $scope.start = $scope.yearAgo;
        $scope.end = $scope.today;
        break;
      case "3": // 30 Days
        $scope.start = $scope.monthAgo;
        $scope.end = $scope.today;
        break;
    }
    if (ticker !== '') {
      $scope.goFetch(ticker);
    }
  };

  $scope.goFetch = function(stockSymbol) {
    labels.length = 0;
    data.length = 0;
    volume.length = 0;
    ticker = stockSymbol;
    if (ticker) {
      $scope.loadingStock = true;
      getStock({
        stock: ticker,
        startDate: $scope.start,
        endDate: $scope.end
      }, 'historicaldata', function(err, quotes) {
        console.log(quotes);
        if (err) {
          console.log(err);
        } else {
          quotes.quote.forEach(function(datum) {
            labels.push(datum.Date);
            data.push(datum.Close);
            volume.push(parseInt(datum.Volume) / 1000000);
          });
          $scope.labels = labels.reverse();
          $scope.data[0] = data.reverse();
          $scope.data[1] = volume.reverse();
          $scope.options.title.text = ticker;
          $scope.datasetOverride[0].label = ticker;
          $scope.loadingStock = false;
          $scope.$apply();
        }
      });
    }
  };

  $scope.datasetOverride = [{
    label: "",
    fill: false,
    lineTension: 0.0,
    borderColor: "rgba(255,105,180,0.4)",
    backgroundColor: "rgba(255,105,180,0.3)",
    pointBorderColor: "rgba(255,105,180,0.4)",
    pointBackgroundColor: "rgba(255,105,180,0.4)",
    pointHoverBackgroundColor: "rgba(255,105,180,0.4)",
    pointHoverBorderColor: "rgba(255,105,180,0.4)",
    pointRadius: 1.6,
    yAxisID: 'y-axis-1'
  }, {
    label: "Vol",
    fill: true,
    lineTension: 0.0,
    borderColor: "rgba(220,220,220,0.2)",
    backgroundColor: "rgba(186,144,255,0.2)",
    borderWidth: 0.01,
    pointRadius: 0,
    pointBorderColor: "rgba(255,105,180,0.4)",
    pointBackgroundColor: "rgba(255,105,180,0.4)",
    pointHoverBackgroundColor: "rgba(186,144,255,0.2)",
    pointHoverBorderColor: "rgba(186,144,255,0.2)",
    showLine: false,
    yAxisID: 'y-axis-2',
    hidden:true
  }];
  $scope.onClick = function(points, evt) {
    //    console.log(points, evt);
  };
  $scope.options = {
    title: {
      display: true,
      text: '',
      fontColor: 'rgba(255,105,180,0.8)',
      fontSize: 16
    },
    tooltips: {
      enabled: true,
      backgroundColor: 'rgba(255,105,180,0.4)',
      displayColors: false
    },
    scales: {
      yAxes: [{
        id: 'y-axis-1',
        ticks: {
          beginAtZero: false,
          fontColor: 'rgba(255,105,180,0.6)'
        },
        scaleLabel: {
          display: true,
          labelString: 'Price (USD)',
          fontColor: 'rgba(255,105,180,0.6)'
        },
        gridLines: {
          display: true,
          color: "rgba(255,105,180,0.1)"
        }
      }, {
        id: 'y-axis-2',
        position: 'right',
        display: false,
        ticks: {
          beginAtZero: false,
          fontColor: 'rgba(186,144,255,0.4)'
        },
        scaleLabel: {
          display: true,
          labelString: 'Traded Volume (Million Shares)',
          fontColor: 'rgba(186,144,255,0.4)'
        },
        gridLines: {
          display: true,
          color: "rgba(186,144,255,0.1)"
        }
      }],
      xAxes: [{
        type: 'time',
        time: {
          displayFormats: {
            month: 'MMM YY'
          },
          unit: 'month'
        }
      }]
    },
  };

}]);

var stocks = {
  DowJones30: [{
    companyName: "3M",
    stockSymbol: "MMM"
  }, {
    companyName: "American Express",
    stockSymbol: "AXP"
  }, {
    companyName: "Apple",
    stockSymbol: "AAPL"
  }, {
    companyName: "Boeing",
    stockSymbol: "BA"
  }, {
    companyName: "Caterpillar",
    stockSymbol: "CAT"
  }, {
    companyName: "Chevron",
    stockSymbol: "CVX"
  }, {
    companyName: "Cisco",
    stockSymbol: "CSCO"
  }, {
    companyName: "Coca-Cola",
    stockSymbol: "KO"
  }, {
    companyName: "Disney",
    stockSymbol: "DIS"
  }, {
    companyName: "E I du Pont de Nemours and Co",
    stockSymbol: "DD"
  }, {
    companyName: "Exxon Mobil",
    stockSymbol: "XOM"
  }, {
    companyName: "General Electric",
    stockSymbol: "GE"
  }, {
    companyName: "Goldman Sachs",
    stockSymbol: "GS"
  }, {
    companyName: "Home Depot",
    stockSymbol: "HD"
  }, {
    companyName: "IBM",
    stockSymbol: "IBM"
  }, {
    companyName: "Intel",
    stockSymbol: "INTC"
  }, {
    companyName: "Johnson & Johnson",
    stockSymbol: "JNJ"
  }, {
    companyName: "JPMorgan Chase",
    stockSymbol: "JPM"
  }, {
    companyName: "McDonald's",
    stockSymbol: "MCD"
  }, {
    companyName: "Merck",
    stockSymbol: "MRK"
  }, {
    companyName: "Microsoft",
    stockSymbol: "MSFT"
  }, {
    companyName: "Nike",
    stockSymbol: "NKE"
  }, {
    companyName: "Pfizer",
    stockSymbol: "PFE"
  }, {
    companyName: "Procter & Gamble",
    stockSymbol: "PG"
  }, {
    companyName: "Travelers",
    stockSymbol: "TRV"
  }, {
    companyName: "United",
    stockSymbol: "UTX"
  }, {
    companyName: "UnitedHealth",
    stockSymbol: "UNH"
  }, {
    companyName: "Verizon",
    stockSymbol: "VZ"
  }, {
    companyName: "Visa",
    stockSymbol: "V"
  }, {
    companyName: "Wal-Mart",
    stockSymbol: "WMT"
  }]
};
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console