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

              
                <script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/microchart.js"></script>
<div id="chartdiv"></div>
<div id="sparklines"></div>
              
            
!

CSS

              
                body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

#chartdiv {
  width: 150px;
  height: 60px;
  position: fixed;
  top: -1000px;
}

svg {
  width: 150px;
  height: 60px;
  float: left;
  margin: 5px;
  overflow: visible;
}
              
            
!

JS

              
                /**
 * ---------------------------------------
 * This demo was created using amCharts 4.
 *
 * For more information visit:
 * https://www.amcharts.com/
 *
 * Documentation is available at:
 * https://www.amcharts.com/docs/v4/
 * ---------------------------------------
 */

// Use microchart theme
am4core.useTheme(am4themes_microchart);

// Function that generates random data
var count = 50;
function getData() {
  if (count > 0) {
    var data = [];
    var visits = 10;
    for (let i = 1; i < 30; i++) {
      visits += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 10);
      data.push({ date: new Date(2018, 0, i), value: visits });
    }
    count--;
    return data;
  }
}

// Cretae chart
var chart = am4core.create("chartdiv", am4charts.XYChart);
chart.maskBullets = false;

// Axes
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());

// Series
var series = chart.series.push(new am4charts.LineSeries());
series.tooltipText = "{date}: [bold]{value}";
series.dataFields.dateX = "date";
series.dataFields.valueY = "value";

// Render data points as bullets
var bullet = series.bullets.push(new am4charts.CircleBullet());
bullet.circle.opacity = 1;
bullet.disabled = true;
bullet.propertyFields.disabled = "disabled";
bullet.circle.radius = 3;

// Start processing charts
processNextChart();

// Generates next chart
function processNextChart() {
  var newData = getData();
  if (newData) {
    // Update chart and generate a snapshot
    series.data = newData;
    series.data[series.data.length - 1].disabled = false;
    series.events.once("dataitemsvalidated", function() {
      createImage();
    });
  }
  else {
    // We're done - no more data. Dispose chart.
    chart.dispose();
  }
}

function createImage() {
  var invalidSprites = am4core.registry.invalidSprites[chart.uid];
  if (invalidSprites && invalidSprites.length) {
    am4core.registry.events.once("exitframe", function() {
      createImage();
    });
  }
  else {
    am4core.registry.events.once("exitframe", function() {
      var target = chart.chartAndLegendContainer;
      var svg = chart.exporting.normalizeSVG(
        chart.exporting.serializeElement(target.dom),
        {},
        target.pixelWidth,
        target.pixelHeight
      );
      var div = document.getElementById("sparklines");
      div.innerHTML += svg;
      processNextChart();
    });
  }
}

              
            
!
999px

Console