// Create a data array with some sample values
var data = [
{ "CountryName": "China", "Pop1995": 1216, "Pop2005": 1297, "Pop2015": 1361, "Pop2025": 1394 },
{ "CountryName": "India", "Pop1995": 920, "Pop2005": 1090, "Pop2015": 1251, "Pop2025": 1396 },
{ "CountryName": "United States", "Pop1995": 266, "Pop2005": 295, "Pop2015": 322, "Pop2025": 351 },
{ "CountryName": "Indonesia", "Pop1995": 197, "Pop2005": 229, "Pop2015": 256, "Pop2025": 277 },
{ "CountryName": "Brazil", "Pop1995": 161, "Pop2005": 186, "Pop2015": 204, "Pop2025": 218 }
];
// Create a chart and bind it to the data array
$("#chart").igCategoryChart({
dataSource: data,
// Set the chart type to column
chartType: "column",
xAxisGap: 0.1,
yAxisMinimumValue: 0,
yAxisMaximumValue: 1500,
yAxisInterval: 250,
yAxisLabel: "Population (in millions)",
xAxisLabel: "Country",
title: "Population per Country",
subtitle: "(Projected population for 2025)",
// Add a custom annotation layer to the chart
customAnnotationLayer: {
// Set the content of the annotation layer to be a function that returns an SVG element
content: function (context) {
// Get the chart width and height
var width = context.width();
var height = context.height();
// Get the chart scale and offset
var scale = context.scale();
var offset = context.offset();
// Get the value of the horizontal line to be the average population of all countries
var value = data.reduce(function (sum, item) {
return sum + item.Pop2025;
}, 0) / data.length;
// Calculate the y position of the horizontal line based on the value, scale, and offset
var y = height - (value * scale.y() + offset.y());
// Create an SVG namespace
var svgns = "http://www.w3.org/2000/svg";
// Create an SVG line element with the desired...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.