This is a weird one - I'm debugging some JavaScript code in Chrome and I've found that when I'm passing parameters to a class function they're not actually getting passed? The weird thing is, sometimes this code works - other times it doesn't.
Here's what I've got (I've trimmed down the code a bit and removed what I think is unnecessary)
<script type="text/javascript">
$(document).ready(function () {
var agentID = 'abcd-1234';
var isCurrent = 'true';
var colourUtilities = new ColorUtilities();
var palette = colourUtilities.GeneratePalette(["#2c2656","#362d68","#3f3579","#483d8b","#51459d","#5a4dae","#6a5db8"]);
GetData();
function GetData() {
var url = 'WebRequest.ashx?agentID=' + agentID + "&isCurrent=" + isCurrent;
$.ajax({
type: 'POST',
url: url,
dataType: 'json',
success: function (data) {
BuildCharts(data);
},
error: function (XMLHttpRequest, status, errorThrown) {
alert(errorThrown);
}
});
}
function BuildCharts(data) {
BuildSummaryBubbleChart(data);
}
function BuildSummaryBubbleChart(data) {
var statusDistributionLabels = [];
var statusDistributionCounts = [];
for (var status in data) {
statusDistributionLabels.push(status);
statusDistributionCounts.push(data[status])
}
var chartBuilder = new ChartBuilder(palette, palette[0]);
var canvasName = "cVacateDistribution";
chartBuilder.BuildBubbleLineChart(canvasName, statusDistributionLabels, statusDistributionCounts, "No data available.");
}
});
This part all works correctly - as you can see when I'm debugging in chrome, everything has a value when I call chartBuilder.BuildBubbleLineChart:
- as you can see, chartBuilder has a value, the canvasName variable has a value and is being passed correctly, the arrays have values.
And yet - continuing to debug, when we jump into the BuildBubbleLineChart function, the values are all undefined:

I can't for the life of my figure out what's wrong. This is the code for the ChartBuilder class (cut down):
function ChartBuilder(palette, mainColor) {
var thisBuilder = {};
var charts = [];
//Builds a horizontal chart of circles separated by lines with labels
thisBuilder.BuildBubbleLineChart = function ({
canvasID,
labels,
data,
noDataMessage = 'No data',
symbols = null } = {}) {
var canvas = document.getElementById(canvasID);
if (canvas == undefined) {
console.log('Error: (BuildBubbleLineChart) Your canvas could not be found');
return;
}
thisBuilder.ClearChart(canvasID);
var ctx = canvas.getContext('2d');
var canvasWidth = canvas.width;
var canvasHeight = canvas.height;
if (NoData(data)) {
canvas.width = 200;
FillNoDataText(ctx, noDataMessage, 100, canvasHeight / 2);
PushCustomChart(canvasID);
return;
}
//etc - goes on to build the chart
}
There's a tonne of other functions within the ChartBuilder class but none are called/used at any point.
My problem is that when I call the BuildBubbleLineChart function and pass it values, it obviously gets to the function and has no values, so it logs the error Error: (BuildBubbleLineChart) Your canvas could not be found and returns.
Any help is greatly appreciated!
thisBuilder.BuildBubbleLineChart, so you have to fix them, or you're calling it incorrectly because you cannot pass it parameters like mentioned in the previous comment. Is it you who wrote this function?