• Demos
    • JavaScript Charts
    • JavaScript StockCharts
  • Download
    • Download Chart
    • Download StockChart
  • Integrations
    • Front End Technology Samples
      • React Charts
      • Angular Charts
      • Vue.js Charts New!
      • jQuery Charts
      • Dashboards
    • Server Side Technology Samples
      • PHP Charts
      • Python Charts New!
      • ASP.NET MVC Charts
      • Spring MVC Charts
      • JSP Charts
  • License
  • Blog
  • Docs
    • Chart Documentation
    • StockChart Documentation
  • Support Forum
    • Chart Support
    • StockChart Support
  • My Account
  • My Account
  • KEY FEATURES
    • Chart with Index / Data Label
    • Chart with Zooming / Panning
    • Chart using JSON Data
    • Chart with Animation
    • Multi Series Chart
    • Chart with Multiple Axes
    • Chart with Crosshair
    • Chart with Scale Breaks
    • Chart with Logarithmic Axis
    • Performance with 50,000 Data Points
    • Responsive Charts
    • Chart with Drilldown
  • LINE CHARTS
    • Line Chart
    • Spline Chart
    • Step Line Chart
  • AREA CHARTS
    • Area Chart
    • Multi Series Area Chart with Date Time Axis
    • Spline Area Chart
    • Step Area Chart
    • Range Area Chart
    • Range Spline Area Chart
    • Stacked Area Chart
    • Stacked Area 100% Chart
  • COLUMN & BAR CHARTS
    • Column Chart
    • Bar Chart
    • Range Column Chart
    • Stacked Column Chart
    • Stacked Column 100% Chart
    • Range Bar Chart
    • Stacked Bar Chart
    • Stacked Bar 100% Chart
    • Waterfall Chart
  • PIE & FUNNEL CHARTS
    • Pie Chart
    • Pie Chart with Index Labels Placed Inside
    • Doughnut Chart
    • Funnel Chart
    • Funnel Chart with Custom Neck
    • Pyramid Chart
  • FINANCIAL CHARTS
    • Candlestick Chart
    • Candlestick Chart from JSON
    • OHLC Chart
  • SCATTER & BUBBLE CHARTS
    • Scatter Chart
    • Scatter Chart with Custom Markers
    • Bubble Chart
  • BOX & WHISKER CHARTS
    • Box and Whisker Chart
    • Box and Whisker Chart with Customization
  • COMBINATION CHARTS
    • Error chart
    • Error Line Chart
    • Combination of Range, Area and Line Charts
  • DYNAMIC CHARTS
    • Dynamic Line Chart
    • Dynamic Column Chart
    • Dynamic Multi Series Chart
  • DATA BINDING
    • Chart from CSV
    • Chart from XML
    • Chart Data from Database
  • REACT, ANGULAR, VUE.JS, JQUERY
    • React Charts
    • Angular Charts
    • Vue.js Charts
    • jQuery Charts
    • JavaScript Charts
  • SERVER SIDE TECHNOLOGIES
    • Python Charts
    • JSP Charts
    • Spring MVC Charts
    • ASP.NET MVC Charts

PHP Stacked Bar Charts & Graphs

Download PHP Chart Samples
  • PHP Chart Samples
  • JavaScript Chart Samples
  • React Chart Samples
  • Angular Chart Samples
  • Vue.js Chart Samples
  • jQuery Chart Samples
  • Python Django Chart Samples
  • ASP.NET Chart Samples
  • JSP Chart Samples
  • Spring MVC Chart Samples
  • Dashboard Samples
  • JavaScript StockChart Samples

Stacked Bar Chart is formed by stacking multiple data-series, one on top of the other. Given example shows simple PHP Stacked Bar Chart that also includes source code that you can try running locally.

  • PHP Code
<?php

$test = array(
	array("label"=> "Sachin Tendulkar", "y"=> 51),
	array("label"=> "Ricky Ponting", "y"=> 41),
	array("label"=> "Kumar Sangakkara", "y"=> 38),
	array("label"=> "Jacques Kallis", "y"=> 45),
	array("label"=> "Mahela Jayawardene", "y"=> 34),
	array("label"=> "Hashim Amla", "y"=> 28),
	array("label"=> "Brian Lara", "y"=> 34),
	array("label"=> "Virat Kohli", "y"=> 20),
	array("label"=> "Rahul Dravid", "y"=> 36),
	array("label"=> "AB de Villiers", "y"=> 21)
);

$odi = array(
	array("label"=> "Sachin Tendulkar", "y"=> 49),
	array("label"=> "Ricky Ponting", "y"=> 30),
	array("label"=> "Kumar Sangakkara", "y"=> 25),
	array("label"=> "Jacques Kallis", "y"=> 17),
	array("label"=> "Mahela Jayawardene", "y"=> 19),
	array("label"=> "Hashim Amla", "y"=> 26),
	array("label"=> "Brian Lara", "y"=> 19),
	array("label"=> "Virat Kohli", "y"=> 32),
	array("label"=> "Rahul Dravid", "y"=> 12),
	array("label"=> "AB de Villiers", "y"=> 25)
);

$t20 = array(
	array("label"=> "Sachin Tendulkar", "y"=> 0),
	array("label"=> "Ricky Ponting", "y"=> 0),
	array("label"=> "Kumar Sangakkara", "y"=> 0),
	array("label"=> "Jacques Kallis", "y"=> 0),
	array("label"=> "Mahela Jayawardene", "y"=> 1),
	array("label"=> "Hashim Amla", "y"=> 0),
	array("label"=> "Brian Lara", "y"=> 0),
	array("label"=> "Virat Kohli", "y"=> 0),
	array("label"=> "Rahul Dravid", "y"=> 0),
	array("label"=> "AB de Villiers", "y"=> 0)
);
	
?>
<!DOCTYPE HTML>
<html>
<head>  
<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
	animationEnabled: true,
	exportEnabled: true,
	theme: "light1", // "light1", "light2", "dark1", "dark2"
	title:{
		text: "Most Number of Centuries across all Formats till 2017"
	},
	axisX:{
		reversed: true
	},
	axisY:{
		includeZero: true
	},
	toolTip:{
		shared: true
	},
	data: [{
		type: "stackedBar",
		name: "Test",
		dataPoints: <?php echo json_encode($test, JSON_NUMERIC_CHECK); ?>
	},{
		type: "stackedBar",
		name: "ODI",
		dataPoints: <?php echo json_encode($odi, JSON_NUMERIC_CHECK); ?>
	},{
		type: "stackedBar",
		name: "T20",
		indexLabel: "#total",
		indexLabelPlacement: "outside",
		indexLabelFontSize: 15,
		indexLabelFontWeight: "bold",
		dataPoints: <?php echo json_encode($t20, JSON_NUMERIC_CHECK); ?>
	}]
});
chart.render();

}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</body>
</html>                              

Chart Customizations

Data sereis color can be changed to make it visually distinct using color. Some other commonly used customizations are showInLegend, shared(in toolTip), dataPointWidth, etc.

© fenopix
  • About Us
  • FAQs
  • Careers
  • Privacy Policy
Server Side Technologies
  • ASP.NET MVC Charts
  • PHP Charts
  • JSP Charts
  • Spring MVC Charts
Front End Technologies
  • JavaScript Charts
  • jQuery Charts
  • React Charts
  • Angular Charts
  • JavaScript StockCharts
Contact
  • Fenopix, Inc.
  • 2093 Philadelphia Pike,
  • #5678, Claymont,
  • Delaware 19703
  • United States Of America