score:0

Accepted answer

try this: get global variable dynamically by name string in javascript

or add your chart to an object of which you can access the keys:

var charts = {};
charts.populationincrease = new chart(...);

function updatechart(chartname, value) {
    charts[chartname].value = value;
}

updatechart('populationincrease', { ... });

score:0

issue you have is that you are trying to access the objects property (getting and setting) however you are trying to access properties of the string $(this).attr("name") where instead you should be using $(this)

see fixed code below

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), $(this).attr("name"),""); //pass in the object and the name
});

function updatechart(chartobject, 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; 
            chartobject.config.data = json.parse(data3); //you are using the object not the string attribute of name
            chartobject.update();

        },  
        error: function (xhr, ajaxoptions, thrownerror) {
       // alert(xhr.status);
        alert(thrownerror);
      }
    });
};

Related Query