cssAudio - ActiveCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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;
}
            
          
!
            
              //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) {
        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
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console