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);
}
});
};
Source: stackoverflow.com
Related Query
- How can i refere to an object variable dynamically?
- How can i iterate or get all object out of array with object key in Chart.js
- how can i reset chartjs object all instances and recreate it from scratch?
- How to generate color code dynamically by swapping 2 characters within a string using PHP
- How to write better code in es6 for formatting an object with array values
- How to destroy chart object in order to change chart data dynamically (Chart.js)?
- How can have variable data be from a url in javascript
- TS how can I use a class variable inside method?
- How to get ChartJs object from dynamically created chart
- How can we type a variable which is a method in TypeScript ? (Using Chart.js)
- How pass a variable from code behind to javascript
- How to run Chart.js samples using source code
- How can i fix my code so i can read my data
- Chart.js variable data how can i make this work?
- How can labels/legends be added for all chart types in chart.js (chartjs.org)?
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
- How can I control the placement of my Chart.JS pie chart's legend, as well as its appearance?
- How can I make two of my lines in Chart JS thicker
- How to modify chartjs tooltip so i can add customized strings in tooltips
- How to push datasets dynamically for chart.js (bar chart)?
- How can I increase the size of the pie (Chart.JS)?
- How can I make a stepline or stepped chart in chart.js or D3?
- How can I draw dotted line using chartjs?
- How to create datasets dynamically for chart.js Line chart?
- How I can prevent of labels overlapping on mobile screen Chart.js
- How can I hide tooltip in Chart.js on a specific data label?
- How can I sort data from highest to lowest in chart.js
- How can configure my y-axis on chart.js?
- How can I remove extra whitespace from the bottom of a line chart in chart.js?
- How can I create a time series line graph in chart.js?
More Query from same tag
- Chart js. How to align text by the center of the tooltip?
- Looping variables or array
- Chart.js with JSON empty
- How can I put my label on the right hand side of my chart in Chartjs
- how to sort tooltip value in Chart.js
- Linear x axis for bar chart chartjs
- How to limit xAxis label in Chart.Js 1.0.2?
- Set different color for each bars using ChartJS in Angular 4
- Chart.js Line, different fill color for negative point
- Hide/disable tootlip on specific graph values
- How to write with good practice?
- Chart.js - tooltiptemplate with one decimal value in pie chart
- how to make a chart linked to the C# database?
- Property 'getContext' does not exist on type 'HTMLElement'
- Inserting Graphs into DomPDF
- ChartJS v3 Migration: how to define annotation plugin?
- combo bar line chart with multiple grouped/stacked datasets
- Chartjs Bar Chart add background color to value labels
- ChartJS AJAX load labels and data
- ChartJS Realtime Animation
- chart.js tooltip keeps remembering old data after update
- zoom and pan on charts in angular
- Chart.js xAxis linear scale : strange behavior
- How to generate chartjs charts to pdf using laravel?
- vue-chart.js : Data available as computed properties, but not showing in chart
- In reactjs doughnut chart, How to reduce the width of the chart
- Chart.JS: Show custom labels permanentely on doughnut chart
- Laravel 5.6 using laracharts. Chart wont render
- Create multiple pie chart simultaneously using chart.js
- Chart.js and Firebase Ionic App Angular 4