Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Bar Chart - logarithmic type if all numbers are zero browser crashes "Out of memory"

Open neway003 opened this issue 9 years ago • 4 comments

For the below bar chart code, type:'logarithmic', If all the vehicle count are zero in data array bowser goes to Out of memory exception , If i remove type:'logarithmic' it works.

  1. chrome browser (Version 59.0.3071.115 (Official Build) (64-bit)) stops with Out of memory exception. scr

  2. Firefox (Version 54.0.1 (32-bit)) not showing any error or graph.

  3. IE (Version 10.0.9200.16384) not showing any error or graph.

  4. Opera (Version 46.0.2597.57 (PGO)) Also stops with Out of memory exception. scro

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<div id="GateChartHolder" style="display: table; width: 100%; height: 400px;"></div>
<script type="text/javascript">
$(document).ready(function () {
	data = [{
		"LaneTitle": "Basement Entrance",
		"VehicleCount": 0
	}, {
		"LaneTitle": "Drop off area",
		"VehicleCount": 0
	}, {
		"LaneTitle": "Parking Entrance",
		"VehicleCount": 0
	}, {
		"LaneTitle": "Parking Exit",
		"VehicleCount": 0
	}];

	$("#GateChartHolder").html("<canvas id=\"gateChart\" width=\"400\" height=\"200\"></canvas>");
	var ctx = document.getElementById("gateChart");
	var vlbl = [];
	var vcount = [];
	$.each(data, function (k, v) {
		vlbl.push(v.LaneTitle);
		vcount.push(v.VehicleCount);
	});

	var myChart = new Chart(ctx, {
		type: 'bar',
		data: {
			labels: vlbl,
			datasets: [{
				label: 'Vehicle Count',
				data: vcount,
				borderWidth: 1
			}]
		},
		options: {
			scales: {
				yAxes: [{
					type: 'logarithmic',
					ticks: {
						callback: function (tick, index, ticks) {
							console.log(tick + "-" + index + "-" + ticks);
							return tick.toLocaleString();
						},
						min: 0
					},
					display: false
				}]
			}
		}
	});
});
</script>

neway003 avatar Jul 27 '17 12:07 neway003

@neway003 could you try v2.6.0 instead of v.2.5.0? I recall seeing and fixing something similar to this then

etimberg avatar Jul 27 '17 22:07 etimberg

Same condition on v2.6.0

neway003 avatar Jul 29 '17 06:07 neway003

Done in #4959

etimberg avatar Dec 12 '17 23:12 etimberg