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

Bar chart Log scale showing x-axis lines below origin line

Open neway003 opened this issue 9 years ago • 4 comments

I have created a bar chart using below code. Which shows one line below x-axis. And also while using logarithmic y-axis shows axis line overlapping if chart is small. How can I show axises in regular interval, Like for this chart [0,500,1000, 5000, 10000..etc].

chartjs issue

<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>
<div id="GateChartHolder" style="display: table; width: 100%; height: 400px;"></div>
<script type="text/javascript">
$(document).ready(function () {
	data = [{
		"LaneTitle": "Basement Entrance",
		"VehicleCount": 258
	}, {
		"LaneTitle": "Drop off area",
		"VehicleCount": 461
	}, {
		"LaneTitle": "Parking Entrance",
		"VehicleCount": 5271
	}, {
		"LaneTitle": "Parking Exit",
		"VehicleCount": 5542
	}];

	$("#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: {
						beginAtZero: true,
						callback: function (tick, index, ticks) {
							return tick.toLocaleString();
						},
						min: 0
					}
				}]
			}
		}
	});
});
</script>

neway003 avatar May 16 '17 06:05 neway003

@neway003 could you put this in a fiddle so that we can debug?

etimberg avatar May 16 '17 11:05 etimberg

Below link to fiddle https://jsfiddle.net/neway003/532zc37o/

neway003 avatar May 16 '17 11:05 neway003

Looks to be related to the min: 0 and beginAtZero: true settings

etimberg avatar May 16 '17 22:05 etimberg

Thankyou, I have commented beginAtZero: true

and kept min: 0 because if one of the data point with value 1 and other one is much bigger like 6000, data point with value 1 is not shown as bar.

Now its working, I have updated the fiddle. Thank you.

And also could you please suggest me how to remove some of the y axis interval shown which are overlapping.

neway003 avatar May 17 '17 04:05 neway003