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

              
                <script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<script src="//www.amcharts.com/lib/4/themes/animated.js"></script>
<div id="chartdiv"></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: 100%;
  height: 300px;
}
              
            
!

JS

              
                /**
 * --------------------------------------------------------
 * This demo was created using amCharts V4 preview release.
 *
 * V4 is the latest installement in amCharts data viz
 * library family, to be released in the first half of
 * 2018.
 *
 * For more information and documentation visit:
 * https://www.amcharts.com/docs/v4/
 * --------------------------------------------------------
 */

// Define nulti-level data
var data = [
  {
    from: "A",
    to: "D",
    value: 10,
    sub: [
      { from: "A1", to: "D1", value: 2 },
      {
        from: "A2",
        to: "D2",
        value: 5,
        sub: [
          { from: "A1-1", to: "D1-1", value: 1 },
          { from: "A1-1", to: "D1-2", value: 1 },
          { from: "A1-2", to: "D1-2", value: 2 },
          { from: "A1-2", to: "D1-3", value: 1 }
        ]
      },
      { from: "A3", to: "D2", value: 3 }
    ]
  },
  {
    from: "B",
    to: "D",
    value: 8,
    sub: [
      { from: "B1", to: "D1", value: 2 },
      { from: "B2", to: "D2", value: 2 },
      { from: "B3", to: "D2", value: 3 },
      { from: "B4", to: "D2", value: 1 }
    ]
  },
  {
    from: "B",
    to: "E",
    value: 4,
    sub: [
      { from: "B1", to: "E1", value: 2 },
      { from: "B2", to: "E2", value: 1 },
      { from: "B2", to: "E3", value: 1 }
    ]
  },
  {
    from: "C",
    to: "E",
    value: 3,
    sub: [
      { from: "C1", to: "E1", value: 2 },
      { from: "C1", to: "E2", value: 1 }
    ]
  }
];

am4core.useTheme(am4themes_animated);

var chart = am4core.create("chartdiv", am4charts.SankeyDiagram);
chart.data = data;
chart.dataFields.fromName = "from";
chart.dataFields.toName = "to";
chart.dataFields.value = "value";

// for right-most label to fit
chart.paddingRight = 40;
chart.paddingBottom = 25;

// Add events on links
chart.links.template.cursorOverStyle = am4core.MouseCursorStyle.pointer;
chart.links.template.events.on("hit", function(ev) {
  chart.colors.reset();
  var linkData = ev.target.dataItem.dataContext;
  if (linkData.sub) {
    chart.data = linkData.sub;
  }
});
              
            
!
999px

Console