how to change object properties by on-click

Multi tool use
Multi tool use


how to change object properties by on-click



I am having object like



funnel chart with options


var positon={
options:{
sort:"desc";
}
}



in that case my chart in reverse position .
But what i need is when i click the button sort must change to "asc" and my chart must be in straight position



i tried the following


$(document).ready(function(){
$("button").click(function(){
console.log("working");
if (config.options.sort == 'asc') {
config.options.sort= 'asc';

} else {
config.options.sort = 'desc';
console.log("calling here 2" + config.options.sort);
}
});
});





idownvotedbecau.se/noattempt
– UncleDave
Jul 2 at 9:06





Hi @ uncle dave i had tried the above code
– pradeep
Jul 2 at 9:16




2 Answers
2



Try this.


var positon ={
options: {
sort:"desc"
}
}

onSortClick() {
positon.options.sort = positon.options.sort === "desc" ? "asc": "desc"
return positon.options.sort;
};



In your plunker do these changes.



Add a button.


<button id="sort-btn">Sort</button>



Add an event listner


document.getElementById("sort-btn").addEventListener("click", function() {
config.options.sort = config.options.sort === "desc" ? "asc" : "desc";
var ctx = document.getElementById("chart-area").getContext("2d");
window.myDoughnut = new Chart(ctx, config);
console.log(config.options.sort);
});





@anurag i had provided my fiddle can u please check
– pradeep
Jul 2 at 9:19





did you add the above functionality to the plunker?
– Anuradha Gunasekara
Jul 2 at 9:23





in plunker i did not added but i tried in the local
– pradeep
Jul 2 at 9:26





I do not know about the graph. But the sort property is changing according to the conditions.
– Anuradha Gunasekara
Jul 2 at 9:30





but i need that to change in the chart bro
– pradeep
Jul 2 at 9:31



It's very simple you just have to create an event listener.


<input type="button" id="myCheck" onclick="reverse()">


function reverse() {
config.options.sort = "asc";
}





let me check this Anurag
– pradeep
Jul 2 at 9:09





For more please check https://stackoverflow.com/questions/38643994/dynamically-update-the-options-of-a-chart-in-chartjs-using-javascript
– Anurag pareek
Jul 2 at 9:10



https://stackoverflow.com/questions/38643994/dynamically-update-the-options-of-a-chart-in-chartjs-using-javascript





bro it tried all the ways but it is not working for me
– pradeep
Jul 2 at 9:14





wait i will provide my fiddle
– pradeep
Jul 2 at 9:14





plnkr.co/edit/JLbO6VObztye9DY5xJfi?p=preview
– pradeep
Jul 2 at 9:18






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

z WQEuFI777ZWLIq1,yiFSeY,YCKdOn1V1E3 Or0ETCUWBxdk,a
ONL5rXV51 bLjy0,X5 AVA36sxIgdpqXgCjxKHaxlT 90 CaB6

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications