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="//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>
<script src="//www.amcharts.com/lib/4/themes/dataviz.js"></script>
<script src="//www.amcharts.com/lib/4/plugins/bullets.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: 500px;
}

              
            
!

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/
 * ---------------------------------------
 */

am4core.useTheme(am4themes_dataviz);

// Create chart instance
var chart = am4core.create("chartdiv", am4core.Container);
chart.width = am4core.percent(100);
chart.height = am4core.percent(100);
chart.layout = "horizontal";

// Colors
var colors = new am4core.ColorSet();

/**
 * =========================================================
 * Flag bullet
 * =========================================================
 */

// Create FlagBullet
var flag = createBulletContainer("FlagBullet");

var flagbullet = flag.createChild(am4plugins_bullets.FlagBullet);
flagbullet.isMeasured = true;
//flagbullet.horizontalCenter = "middle";
//flagbullet.verticalCenter = "top";
flagbullet.align = "center";
flagbullet.y = 150;
flagbullet.label.text = "Hello,\nWorld!";
flagbullet.label.fill = am4core.color("#fff");
flagbullet.background.waveLength = 15;
flagbullet.background.fill = colors.getIndex(1);
flagbullet.pole.strokeWidth = 2;
flagbullet.pole.stroke = colors.getIndex(0);

createSlider(flag, "background.waveLength = ", 0.5, function(ev) {
  var min = 0, max = 30;
  var value = Math.round((max - min) * ev.target.start + min);
  this.background.waveLength = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, flagbullet, 2);

createSlider(flag, "pole.strokeWidth = ", 0, function(ev) {
  var min = 1, max = 10;
  var value = Math.round((max - min) * ev.target.start + min);
  this.pole.strokeWidth = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, flagbullet, 1);

createSlider(flag, "poleLength = ", 0.6, function(ev) {
  var min = -100, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.poleHeight = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, flagbullet, 0);

/**
 * =========================================================
 * Pin bullet
 * =========================================================
 */

// Create FlagBullet
var pin = createBulletContainer("PinBullet");

var pinbullet = pin.createChild(am4plugins_bullets.PinBullet);
pinbullet.isMeasured = true;
//pinbullet.horizontalCenter = "middle";
//pinbullet.verticalCenter = "top";
pinbullet.align = "center";
pinbullet.y = 150;
pinbullet.background.fill = colors.getIndex(1);


pinbullet.image = new am4core.Image();
pinbullet.image.href = "https://placekitten.com/150/150";

createSlider(pin, "background.radius = ", 0.2, function(ev) {
  var min = 10, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.background.radius = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, pinbullet, 0);

createSlider(pin, "background.pointerAngle = ", 0.75, function(ev) {
  var min = -180, max = 180;
  var value = Math.round((max - min) * ev.target.start + min);
  this.background.pointerAngle = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, pinbullet, 1);

createSlider(pin, "background.pointerLength = ", 0.4, function(ev) {
  var min = 1, max = 50;
  var value = Math.round((max - min) * ev.target.start + min);
  this.background.pointerLength = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, pinbullet, 2);

createSlider(pin, "background.pointerBaseWidth = ", 0.4, function(ev) {
  var min = 1, max = 50;
  var value = Math.round((max - min) * ev.target.start + min);
  this.background.pointerBaseWidth = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, pinbullet, 3);

createSlider(pin, "circle.radius = ", 0.85, function(ev) {
  var min = 0, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.circle.radius = am4core.percent(value);
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, pinbullet, 4, true);

/**
 * =========================================================
 * Star
 * =========================================================
 */

// Create FlagBullet
var star = createBulletContainer("Star");

var starbullet = star.createChild(am4plugins_bullets.Star);
starbullet.isMeasured = true;
starbullet.align = "center";
starbullet.y = 120;
starbullet.fill = colors.getIndex(1);

createSlider(star, "radius = ", 0.2, function(ev) {
  var min = 10, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.radius = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 0);

createSlider(star, "innerRadius = ", 0.5, function(ev) {
  var min = 1, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.innerRadius = am4core.percent(value);
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 1, true);

createSlider(star, "pointCount = ", 0.15, function(ev) {
  var min = 3, max = 30;
  var value = Math.round((max - min) * ev.target.start + min);
  this.pointCount = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 2);

createSlider(star, "arc = ", 1, function(ev) {
  var min = 0, max = 360;
  var value = Math.round((max - min) * ev.target.start + min);
  this.arc = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 3);

createSlider(star, "innerCornerRadius = ", 0, function(ev) {
  var min = 0, max = 20;
  var value = Math.round((max - min) * ev.target.start + min);
  this.innerCornerRadius = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 4);

createSlider(star, "cornerRadius = ", 0, function(ev) {
  var min = 0, max = 20;
  var value = Math.round((max - min) * ev.target.start + min);
  this.cornerRadius = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, starbullet, 5);

/**
 * =========================================================
 * Pointed circle
 * =========================================================
 */

// Create FlagBullet
var circle = createBulletContainer("PointedCircle");

var circlebullet = circle.createChild(am4plugins_bullets.PointedCircle);
circlebullet.isMeasured = true;
//circlebullet.horizontalCenter = "middle";
//circlebullet.verticalCenter = "top";
circlebullet.align = "center";
circlebullet.y = 150;
circlebullet.fill = colors.getIndex(1);

createSlider(circle, "radius = ", 0.1, function(ev) {
  var min = 10, max = 100;
  var value = Math.round((max - min) * ev.target.start + min);
  this.radius = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, circlebullet, 0);

createSlider(circle, "pointerAngle = ", 0.75, function(ev) {
  var min = -180, max = 180;
  var value = Math.round((max - min) * ev.target.start + min);
  this.pointerAngle = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, circlebullet, 1);

createSlider(circle, "pointerLength = ", 0.3, function(ev) {
  var min = 1, max = 50;
  var value = Math.round((max - min) * ev.target.start + min);
  this.pointerLength = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, circlebullet, 2);

createSlider(circle, "pointerBaseWidth = ", 0.2, function(ev) {
  var min = 1, max = 50;
  var value = Math.round((max - min) * ev.target.start + min);
  this.pointerBaseWidth = value;
  ev.target.parent.dataItem.value = value;
  ev.target.parent.deepInvalidate();
}, circlebullet, 3);


// Creates a container
function createBulletContainer(title) {
  var bulletContainer = chart.createChild(am4core.Container);
  bulletContainer.width = am4core.percent(25);
  bulletContainer.height = am4core.percent(100);
  bulletContainer.layout = "absolute";
  bulletContainer.background.stroke = am4core.color("#eee");
  bulletContainer.padding(10, 10, 10, 10);
  bulletContainer.margin(10, 10, 10, 10);

  var label = bulletContainer.createChild(am4core.Label);
  label.text = title;
  label.align = "center";
  label.fontSize = 20;
  
  return bulletContainer;
}

// Creates a slider
function createSlider(parent, title, position, callback, scope, shift, percent) {
  var sliderContainer = parent.createChild(am4core.Container)
  sliderContainer.width = am4core.percent(100);
  sliderContainer.layout = "vertical";
  sliderContainer.dataItem = new am4core.DataItem();
  sliderContainer.dataItem.value = 10;
  sliderContainer.valign = "bottom";
  sliderContainer.dy = shift * -55;
  
  var label = sliderContainer.createChild(am4core.Label);
  if (percent) {
    label.text = title + "[bold]am4core.percent({value})";
  }
  else {
    label.text = title + "[bold]{value}";
  }
  label.align = "center";
  label.fontSize = 9;
  
  var slider = sliderContainer.createChild(am4core.Slider)
  slider.width = am4core.percent(80);
  slider.align = "center";
  slider.start = position;
  slider.events.on("rangechanged", callback, scope);
  return sliderContainer;
}
              
            
!
999px

Console