Im creating multiple charts at the same page, now i want a smart function to either update a single chart or all of them
It works fine when i hard code the object name but i want to be able to get the object name from the button it was executed from
<button class="update" name="prodChart1" funtionName="f_A_GetTotalWorkedHours"> Test</button>
var prodChart1 = document.getElementById('ProdChart1');
var prodChart1 = new Chart( prodChart1, {
type: "line",
data: <%=f_A_GetTotalWorkedHours(Dateadd("d",-2,Date), Date, 48, Line, "")%>,
options: {
color: 'red',
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
$(".update").click(function(){
UpdateChart($(this).attr("name"),"")
});
function UpdateChart(chartName, aFunction) {
$.ajax({
type: 'POST', //post method
url: 'AnalyticsAPI.asp?',
dataType: "text",
data: {requestParam: 'f_A_GetTotalWorkedHours|'+ getParam()[0] +'|'+ getParam()[1] +'|48' },
success: function (result, textStatus, jqXHR)
{
data3= result;
chartName.config.data = JSON.parse(data3);
chartName.update();
},
error: function (xhr, ajaxOptions, thrownError) {
// alert(xhr.status);
alert(thrownError);
}
});
};
So the "update" function should get the name of the existing chart object, the object name is part of the button name attribute. The error i get is that "UpdateChart(chartName, aFunction)" chartname isnt a object. If i would hardcode the object name in the call it works.