Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <!-- Chartworks JS -->
<script src="https://content.markitcdn.com/www.chartworks.io/content/chartworks/dist/1.4.11/js/chartworks.min.js"></script>

<div class="chart" id="chartTarget"></div>
              
            
!

CSS

              
                html, body {
	height: 100%;
	margin: 0;
	overflow: hidden;
	background-color: #000;
}
.chart {
	height: 100%;
}
a {
  color: #337ab7;
  text-decoration: none;
}
              
            
!

JS

              
                new ChartworksBuilder({
  "token": "demo-token",
  "target": "#chartTarget",
  "symbol": "AAPL",
  "exchange": "NSQ",
  "timeframe": "1y",
  "realTime": false,
  "typeAheadAPI": "https://api.markitondemand.com/apiman-gateway/MOD/chartworks-xref/1.0/xref/predictive?search=%s",
  "compareMenuOptions": [{
    "symbol": "INFO",
    "exchange": "NYSE",
    "displayName": "IHS Markit Ltd."
  }],
  "cultureCode": "en-US",
  "style.indicator.price.lineColor": "orange",
  "style.indicator.price.fillColor": "rgba(95, 179, 241, 0.1)",
  "style.indicator.price.lineWidth": "3",
  "panel.lower.indicator": "Volume",
  "feature.symbolSearch": true,
  "feature.comparison": true,
  "feature.timeframe": true,
  "feature.indicators": true,
  "feature.intraday": true,
  "feature.events": true,
  "feature.markerType": true,
  "feature.saveLoad": true,
  "feature.share": true,
  "feature.tools": true,
  "theme": "dark",
  "onShare": function(args) {
    var sharePenURL = "https://codepen.io/chartworks/pen/ZpgQEb?chartID=" + args.chartID;
    
    // Display Dialog with link to our chart
    this.showDialog("<a href=" + sharePenURL + " target=\"_blank\">View Your Shared Chart in CodePen</a>");
  },
  "onPrimarySymbolChange": function(args) {
    console.log(args.symbol, args.exchangeId);

    // Display a nice message when trying to get unentitled data
    if (args.symbol != "AAPL" && args.symbol != "INFO") {
      this.showDialog("Alert", "This demo is only entitled to symbols AAPL on the NASDAQ and INFO on the NYSE. All other symbols will fail.");
    }
  },
  "onAPIError": function(apiError) {
    // handle 401 (unauthorized)
    if (apiError.status === 401) {
      // show dialog that we are getting a new token
      this.showDialog("Token expired", "Loading new token...");

      // use getInvalidTokenCount to ensure we don't get stuck in an
      // endless loop if we keep creating bad tokens
      if (this.getInvalidTokenCount() < 5) {
        var objChart = this;
        getNewToken(function(newToken) {
          // set token
          objChart.setConfigParam("token", newToken);

          // load data
          objChart.loadData();
        });
      } else { // fail after 5 unsuccessful tries
        this.showDialog("Warning", "Max number of auth attempts reached. Your token generation is no good!");
      }
    } else { // print other errors in the console
      console.log(apiError.status, apiError.statusMsg);
    }
  }
});

// Your code should generate a new token.
// This is just an example
function getNewToken(onComplete) {
  // timeout to simulate a slow request
  setTimeout(function() {
    var token = "demo-token";
    onComplete(token);
  }, 1000);
}
              
            
!
999px

Console