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 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.

            
              <body>
  <div id="chart"></div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.14.1/moment.js"></script>
  <script src="https://code.highcharts.com/stock/highstock.js"></script>
</body>
            
          
!
            
              $(document).ready(function(){
      
  // Chart Initialization
  var chart = new Highcharts.StockChart({
    chart: {
      renderTo: 'chart' 
    },
    title: {
      text: 'Daily Precipitation' 
    },
    yAxis: {
      labels: {
        formatter: function(){
          return this.value + ' mm';  
        }
      }
    },
    series: []  
  });  


  // getLocationData Function
  function getLocationData(request, onSuccess){

    // Construct URL  
    var url = 'https://insight.api.wdtinc.com/';
    url += request.endpoint + '/';
    url += request.latitude + '/' + request.longitude;  

    // Request Precipitation Data
    $.ajax({
      url: url,
      beforeSend: function(xhr){
        xhr.setRequestHeader("Authorization", "Basic " + btoa(request.appId + ":" + request.appKey));
        xhr.setRequestHeader("Accept", "application/vnd.wdt+json; version=1");
      },
      data: {
        start: moment(request.start).format('YYYY-MM-DD'),
        end: moment(request.end).format('YYYY-MM-DD') 
      },
      dataType: 'json',
      cache: false,
      success: onSuccess,
      error: function(){
        console.log('Whoops, something went wrong.');
      }
    }); 
  }

  // onSuccess Function 
  function onSuccess(data){
    var seriesData = data.series.map(function(point){
      return [parseInt(moment(point.validDate).format('x')),
              point.value];

    });
    chart.addSeries({
      name: data.latitude + ', ' + data.longitude,
      data: seriesData
    });
  }

  // Request OKC Daily Precip
  getLocationData({
    endpoint: 'daily-precipitation',
    latitude: 35.4,
    longitude: -97.5,
    start: '2016-06-01',
    end: '2016-06-30',
    appId: '114e04e1',
    appKey: 'd22d2cc81614aee4afe2f804238e3959'
  }, onSuccess);

  // Request San Francisco Daily Precip
  getLocationData({
    endpoint: 'daily-precipitation',
    latitude: 30.3,
    longitude: -81.6,
    start: '2016-06-01',
    end: '2016-06-30',
    appId: '114e04e1',
    appKey: 'd22d2cc81614aee4afe2f804238e3959'
  }, onSuccess);

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