Annotating Charts
A demo of amCharts 4, the previous version. For a new project, start from the amCharts 5 demos.
With Annotation plugin, bundled with amCharts 4, you can enable powerful annotation features for your users.
Best of all, annotations are serializable, and can be saved and reloaded later, as well as added to the live chart and exported as image.
Open in:
Code
JavaScript
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.PieChart);
// Add data
chart.data = [ {
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czechia",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
} ];
// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.stroke = am4core.color("#fff");
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;
// This creates initial animation
pieSeries.hiddenState.properties.opacity = 1;
pieSeries.hiddenState.properties.endAngle = -90;
pieSeries.hiddenState.properties.startAngle = -90;
// Annotation
var annotation = chart.plugins.push(new am4plugins_annotation.Annotation());
annotation.data = {"version":"3.1.0","objects":[{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":232.5,"top":142,"width":40,"height":37,"fill":"#cc0000","stroke":"#cc0000","strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":6.57,"scaleY":6.57,"angle":0,"flipX":false,"flipY":false,"opacity":0.4,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",24,43],["l",-3,-3],["C",11,31,4,25,4,17],["C",4,11,9,6,15,6],["c",3,0,7,2,9,4],["c",2,-2,6,-4,9,-4],["c",6,0,11,5,11,11],["c",0,8,-7,14,-17,23],["l",-3,3],["z"]]},{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":3.65,"top":4,"width":230,"height":129,"fill":null,"stroke":"rgba(0,204,0,0.6)","strokeWidth":4,"strokeDashArray":null,"strokeLineCap":"round","strokeDashOffset":0,"strokeLineJoin":"round","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",174.65225,26.004],["Q",174.65625,26,174.65625,25.5],["Q",174.65625,25,175.65625,24.5],["Q",176.65625,24,176.65625,22.5],["Q",176.65625,21,177.65625,20],["Q",178.65625,19,178.65625,18.5],["Q",178.65625,18,179.65625,17],["Q",180.65625,16,180.65625,15.5],["Q",180.65625,15,181.65625,14],["Q",182.65625,13,183.65625,12],["Q",184.65625,11,185.65625,10],["Q",186.65625,9,188.65625,8.5],["Q",190.65625,8,191.65625,7.5],["Q",192.65625,7,195.65625,6.5],["Q",198.65625,6,201.65625,5.5],["Q",204.65625,5,207.65625,4.5],["Q",210.65625,4,213.65625,3.5],["Q",216.65625,3,220.65625,2.5],["Q",224.65625,2,228.65625,2],["Q",232.65625,2,236.65625,1.5],["Q",240.65625,1,244.65625,1],["Q",248.65625,1,252.65625,1],["Q",256.65625,1,258.65625,1],["Q",260.65625,1,264.65625,1],["Q",268.65625,1,269.65625,1],["Q",270.65625,1,273.65625,1],["Q",276.65625,1,278.65625,1],["Q",280.65625,1,282.65625,1.5],["Q",284.65625,2,286.65625,2],["Q",288.65625,2,289.65625,2.5],["Q",290.65625,3,292.65625,3.5],["Q",294.65625,4,297.65625,5],["Q",300.65625,6,302.65625,6.5],["Q",304.65625,7,308.65625,8],["Q",312.65625,9,314.65625,10.5],["Q",316.65625,12,320.65625,13],["Q",324.65625,14,328.65625,15.5],["Q",332.65625,17,336.65625,18.5],["Q",340.65625,20,345.65625,22],["Q",350.65625,24,354.65625,25.5],["Q",358.65625,27,362.65625,28.5],["Q",366.65625,30,370.65625,31.5],["Q",374.65625,33,376.65625,34.5],["Q",378.65625,36,381.65625,37.5],["Q",384.65625,39,386.65625,41],["Q",388.65625,43,390.65625,44],["Q",392.65625,45,394.65625,47],["Q",396.65625,49,396.65625,50],["Q",396.65625,51,397.65625,52.5],["Q",398.65625,54,399.65625,54.5],["Q",400.65625,55,400.65625,56],["Q",400.65625,57,400.65625,58.5],["Q",400.65625,60,400.65625,60.5],["Q",400.65625,61,401.65625,62],["Q",402.65625,63,402.65625,65],["Q",402.65625,67,402.65625,67.5],["Q",402.65625,68,402.65625,70.5],["Q",402.65625,73,402.65625,73.5],["Q",402.65625,74,403.65625,76],["Q",404.65625,78,404.65625,79.5],["Q",404.65625,81,404.65625,82.5],["Q",404.65625,84,404.65625,85.5],["Q",404.65625,87,404.65625,88.5],["Q",404.65625,90,404.65625,91],["Q",404.65625,92,404.65625,94],["Q",404.65625,96,404.65625,97],["Q",404.65625,98,404.65625,99.5],["Q",404.65625,101,404.65625,102.5],["Q",404.65625,104,404.65625,105],["Q",404.65625,106,404.65625,108],["Q",404.65625,110,404.15625,111],["Q",403.65625,112,403.15625,112.5],["Q",402.65625,113,401.65625,114.5],["Q",400.65625,116,399.65625,117],["Q",398.65625,118,397.65625,119],["Q",396.65625,120,395.15625,121],["Q",393.65625,122,391.65625,122.5],["Q",389.65625,123,388.15625,124],["Q",386.65625,125,383.65625,125.5],["Q",380.65625,126,377.15625,127],["Q",373.65625,128,370.65625,128],["Q",367.65625,128,364.15625,128.5],["Q",360.65625,129,356.65625,129],["Q",352.65625,129,348.65625,129.5],["Q",344.65625,130,341.15625,130],["Q",337.65625,130,334.15625,130],["Q",330.65625,130,326.65625,129.5],["Q",322.65625,129,319.65625,129],["Q",316.65625,129,312.65625,128.5],["Q",308.65625,128,306.65625,127.5],["Q",304.65625,127,302.15625,126],["Q",299.65625,125,296.65625,124],["Q",293.65625,123,291.15625,122],["Q",288.65625,121,286.65625,120.5],["Q",284.65625,120,282.15625,118],["Q",279.65625,116,276.65625,115],["Q",273.65625,114,270.65625,112.5],["Q",267.65625,111,264.15625,110],["Q",260.65625,109,258.15625,107],["Q",255.65625,105,252.15625,104],["Q",248.65625,103,246.15625,102],["Q",243.65625,101,239.65625,99.5],["Q",235.65625,98,233.15625,96],["Q",230.65625,94,228.65625,93],["Q",226.65625,92,223.65625,90.5],["Q",220.65625,89,219.15625,88],["Q",217.65625,87,214.65625,85.5],["Q",211.65625,84,211.15625,83],["Q",210.65625,82,209.15625,80.5],["Q",207.65625,79,207.15625,78],["Q",206.65625,77,205.65625,76.5],["Q",204.65625,76,204.15625,74.5],["Q",203.65625,73,203.15625,71.5],["Q",202.65625,70,202.65625,69],["Q",202.65625,68,201.65625,66],["Q",200.65625,64,200.15625,62.5],["Q",199.65625,61,199.65625,59],["Q",199.65625,57,199.15625,55.5],["Q",198.65625,54,198.65625,53],["Q",198.65625,52,198.65625,50.5],["Q",198.65625,49,198.65625,47],["Q",198.65625,45,198.65625,44],["Q",198.65625,43,198.65625,42.5],["Q",198.65625,42,198.65625,41.5],["L",198.65625,40.996]]},{"type":"textbox","version":"3.1.0","originX":"left","originY":"top","left":16.15,"top":148.2,"width":106.64,"height":48.82,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"text":"Needs improvement","fontSize":20,"fontWeight":400,"fontFamily":"Times New Roman","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"left","textBackgroundColor":"","charSpacing":0,"minWidth":20,"splitByGrapheme":false,"styles":{}},{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":18.95,"top":106.96,"width":44,"height":40,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":0.81,"scaleY":0.81,"angle":347,"flipX":false,"flipY":false,"opacity":0.6,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",2,42],["h",8],["V",18],["H",2],["v",24],["z"],["m",44,-22],["c",0,-2,-2,-4,-4,-4],["H",29],["l",2,-9],["V",6],["l",-1,-2],["l",-2,-2],["l",-13,13],["l",-1,3],["v",20],["c",0,2,2,4,4,4],["h",18],["l",4,-2],["l",6,-15],["v",-5],["z"]]}]};
HTML
<div id="chartdiv"></div>
CSS
#chartdiv {
width: 742px;
height: 500px;
}
.amcharts-amexport-icon {
min-width: 30px;
min-height: 30px;
}
Resources
https://cdn.amcharts.com/lib/4/core.js
https://cdn.amcharts.com/lib/4/charts.js
https://cdn.amcharts.com/lib/4/plugins/annotation.js
https://cdn.amcharts.com/lib/4/themes/animated.js
All in one page
<!-- Resources -->
<script src="https://cdn.amcharts.com/lib/4/core.js"></script>
<script src="https://cdn.amcharts.com/lib/4/charts.js"></script>
<script src="https://cdn.amcharts.com/lib/4/plugins/annotation.js"></script>
<script src="https://cdn.amcharts.com/lib/4/themes/animated.js"></script>
<!-- Chart code -->
<script>
// Themes begin
am4core.useTheme(am4themes_animated);
// Themes end
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.PieChart);
// Add data
chart.data = [ {
"country": "Lithuania",
"litres": 501.9
}, {
"country": "Czechia",
"litres": 301.9
}, {
"country": "Ireland",
"litres": 201.1
}, {
"country": "Germany",
"litres": 165.8
}, {
"country": "Australia",
"litres": 139.9
}, {
"country": "Austria",
"litres": 128.3
}, {
"country": "UK",
"litres": 99
}, {
"country": "Belgium",
"litres": 60
}, {
"country": "The Netherlands",
"litres": 50
} ];
// Add and configure Series
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "litres";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.stroke = am4core.color("#fff");
pieSeries.slices.template.strokeWidth = 2;
pieSeries.slices.template.strokeOpacity = 1;
// This creates initial animation
pieSeries.hiddenState.properties.opacity = 1;
pieSeries.hiddenState.properties.endAngle = -90;
pieSeries.hiddenState.properties.startAngle = -90;
// Annotation
var annotation = chart.plugins.push(new am4plugins_annotation.Annotation());
annotation.data = {"version":"3.1.0","objects":[{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":232.5,"top":142,"width":40,"height":37,"fill":"#cc0000","stroke":"#cc0000","strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":6.57,"scaleY":6.57,"angle":0,"flipX":false,"flipY":false,"opacity":0.4,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",24,43],["l",-3,-3],["C",11,31,4,25,4,17],["C",4,11,9,6,15,6],["c",3,0,7,2,9,4],["c",2,-2,6,-4,9,-4],["c",6,0,11,5,11,11],["c",0,8,-7,14,-17,23],["l",-3,3],["z"]]},{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":3.65,"top":4,"width":230,"height":129,"fill":null,"stroke":"rgba(0,204,0,0.6)","strokeWidth":4,"strokeDashArray":null,"strokeLineCap":"round","strokeDashOffset":0,"strokeLineJoin":"round","strokeMiterLimit":10,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",174.65225,26.004],["Q",174.65625,26,174.65625,25.5],["Q",174.65625,25,175.65625,24.5],["Q",176.65625,24,176.65625,22.5],["Q",176.65625,21,177.65625,20],["Q",178.65625,19,178.65625,18.5],["Q",178.65625,18,179.65625,17],["Q",180.65625,16,180.65625,15.5],["Q",180.65625,15,181.65625,14],["Q",182.65625,13,183.65625,12],["Q",184.65625,11,185.65625,10],["Q",186.65625,9,188.65625,8.5],["Q",190.65625,8,191.65625,7.5],["Q",192.65625,7,195.65625,6.5],["Q",198.65625,6,201.65625,5.5],["Q",204.65625,5,207.65625,4.5],["Q",210.65625,4,213.65625,3.5],["Q",216.65625,3,220.65625,2.5],["Q",224.65625,2,228.65625,2],["Q",232.65625,2,236.65625,1.5],["Q",240.65625,1,244.65625,1],["Q",248.65625,1,252.65625,1],["Q",256.65625,1,258.65625,1],["Q",260.65625,1,264.65625,1],["Q",268.65625,1,269.65625,1],["Q",270.65625,1,273.65625,1],["Q",276.65625,1,278.65625,1],["Q",280.65625,1,282.65625,1.5],["Q",284.65625,2,286.65625,2],["Q",288.65625,2,289.65625,2.5],["Q",290.65625,3,292.65625,3.5],["Q",294.65625,4,297.65625,5],["Q",300.65625,6,302.65625,6.5],["Q",304.65625,7,308.65625,8],["Q",312.65625,9,314.65625,10.5],["Q",316.65625,12,320.65625,13],["Q",324.65625,14,328.65625,15.5],["Q",332.65625,17,336.65625,18.5],["Q",340.65625,20,345.65625,22],["Q",350.65625,24,354.65625,25.5],["Q",358.65625,27,362.65625,28.5],["Q",366.65625,30,370.65625,31.5],["Q",374.65625,33,376.65625,34.5],["Q",378.65625,36,381.65625,37.5],["Q",384.65625,39,386.65625,41],["Q",388.65625,43,390.65625,44],["Q",392.65625,45,394.65625,47],["Q",396.65625,49,396.65625,50],["Q",396.65625,51,397.65625,52.5],["Q",398.65625,54,399.65625,54.5],["Q",400.65625,55,400.65625,56],["Q",400.65625,57,400.65625,58.5],["Q",400.65625,60,400.65625,60.5],["Q",400.65625,61,401.65625,62],["Q",402.65625,63,402.65625,65],["Q",402.65625,67,402.65625,67.5],["Q",402.65625,68,402.65625,70.5],["Q",402.65625,73,402.65625,73.5],["Q",402.65625,74,403.65625,76],["Q",404.65625,78,404.65625,79.5],["Q",404.65625,81,404.65625,82.5],["Q",404.65625,84,404.65625,85.5],["Q",404.65625,87,404.65625,88.5],["Q",404.65625,90,404.65625,91],["Q",404.65625,92,404.65625,94],["Q",404.65625,96,404.65625,97],["Q",404.65625,98,404.65625,99.5],["Q",404.65625,101,404.65625,102.5],["Q",404.65625,104,404.65625,105],["Q",404.65625,106,404.65625,108],["Q",404.65625,110,404.15625,111],["Q",403.65625,112,403.15625,112.5],["Q",402.65625,113,401.65625,114.5],["Q",400.65625,116,399.65625,117],["Q",398.65625,118,397.65625,119],["Q",396.65625,120,395.15625,121],["Q",393.65625,122,391.65625,122.5],["Q",389.65625,123,388.15625,124],["Q",386.65625,125,383.65625,125.5],["Q",380.65625,126,377.15625,127],["Q",373.65625,128,370.65625,128],["Q",367.65625,128,364.15625,128.5],["Q",360.65625,129,356.65625,129],["Q",352.65625,129,348.65625,129.5],["Q",344.65625,130,341.15625,130],["Q",337.65625,130,334.15625,130],["Q",330.65625,130,326.65625,129.5],["Q",322.65625,129,319.65625,129],["Q",316.65625,129,312.65625,128.5],["Q",308.65625,128,306.65625,127.5],["Q",304.65625,127,302.15625,126],["Q",299.65625,125,296.65625,124],["Q",293.65625,123,291.15625,122],["Q",288.65625,121,286.65625,120.5],["Q",284.65625,120,282.15625,118],["Q",279.65625,116,276.65625,115],["Q",273.65625,114,270.65625,112.5],["Q",267.65625,111,264.15625,110],["Q",260.65625,109,258.15625,107],["Q",255.65625,105,252.15625,104],["Q",248.65625,103,246.15625,102],["Q",243.65625,101,239.65625,99.5],["Q",235.65625,98,233.15625,96],["Q",230.65625,94,228.65625,93],["Q",226.65625,92,223.65625,90.5],["Q",220.65625,89,219.15625,88],["Q",217.65625,87,214.65625,85.5],["Q",211.65625,84,211.15625,83],["Q",210.65625,82,209.15625,80.5],["Q",207.65625,79,207.15625,78],["Q",206.65625,77,205.65625,76.5],["Q",204.65625,76,204.15625,74.5],["Q",203.65625,73,203.15625,71.5],["Q",202.65625,70,202.65625,69],["Q",202.65625,68,201.65625,66],["Q",200.65625,64,200.15625,62.5],["Q",199.65625,61,199.65625,59],["Q",199.65625,57,199.15625,55.5],["Q",198.65625,54,198.65625,53],["Q",198.65625,52,198.65625,50.5],["Q",198.65625,49,198.65625,47],["Q",198.65625,45,198.65625,44],["Q",198.65625,43,198.65625,42.5],["Q",198.65625,42,198.65625,41.5],["L",198.65625,40.996]]},{"type":"textbox","version":"3.1.0","originX":"left","originY":"top","left":16.15,"top":148.2,"width":106.64,"height":48.82,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"text":"Needs improvement","fontSize":20,"fontWeight":400,"fontFamily":"Times New Roman","fontStyle":"normal","lineHeight":1.16,"underline":false,"overline":false,"linethrough":false,"textAlign":"left","textBackgroundColor":"","charSpacing":0,"minWidth":20,"splitByGrapheme":false,"styles":{}},{"type":"path","version":"3.1.0","originX":"left","originY":"top","left":18.95,"top":106.96,"width":44,"height":40,"fill":"#000000","stroke":null,"strokeWidth":1,"strokeDashArray":null,"strokeLineCap":"butt","strokeDashOffset":0,"strokeLineJoin":"miter","strokeMiterLimit":4,"scaleX":0.81,"scaleY":0.81,"angle":347,"flipX":false,"flipY":false,"opacity":0.6,"shadow":null,"visible":true,"clipTo":null,"backgroundColor":"","fillRule":"nonzero","paintFirst":"fill","globalCompositeOperation":"source-over","transformMatrix":null,"skewX":0,"skewY":0,"path":[["M",2,42],["h",8],["V",18],["H",2],["v",24],["z"],["m",44,-22],["c",0,-2,-2,-4,-4,-4],["H",29],["l",2,-9],["V",6],["l",-1,-2],["l",-2,-2],["l",-13,13],["l",-1,3],["v",20],["c",0,2,2,4,4,4],["h",18],["l",4,-2],["l",6,-15],["v",-5],["z"]]}]};
</script>
<!-- HTML -->
<div id="chartdiv"></div>