Topic: Dynamically update mdb-simple-chart data
Dharmendra Prasad free asked 5 years ago
Expected behavior Should be able to change the value of simple chart from angular typescript code in the component.
Actual behavior Hi, I am not able to update the simple chart data dynamically. It is fixed to initial value (which is zero)
Resources (screenshots, code snippets etc.)
I dynamically set the value of jobsAssigned in the component but unfortunately only the text in the chart changes the rail remains at zero
See screenshot.
Damian Gemza staff answered 5 years ago
Dear @Dharmendra Prasad
You can change the font size and font color of the text inside the chart canvas by using css rules.
Please add the below code to the component stylesheet:
.percent {
color: red;
}
There's no possibility to put there HTML string, so there's no possibility to style the text there like on your picture.
Best Regards,
Damian
Dharmendra Prasad free answered 5 years ago
Thanks for the response! I realized that the thing works partially. Somehow my percent value was subjected to change based on a Subject. The first time the page loads, it didn't really change the chart.
I realize that in the component, I need to initialize the value of percent to some number. I cant leave it undefined. After I changed declared the value and assigned it to 0. Everything works as expected.
Dharmendra Prasad free commented 5 years ago
On a different note! Would you be able to suggest me how to change the font color and size of the label inside the chart? ' xx% 'Can I also add some more text in that label?
Trying to achieve something like this.
I know about the customText field. Its not serving the purpose bcoz it takes a string and not an html string
Damian Gemza staff answered 5 years ago
Dear @Dharmendra Prasad
I have tried to reproduce your problem, but without success - I'm able to change dynamically value of mdb-simple-chart
component.
Please take a look at the below code:
.html:
<div class="text-center">
<mdb-simple-chart [percent]="percent" [barColor]="'4CAF50'" [animate]="{duration: 1000, enabled: true}"></mdb-simple-chart>
<h5>
<mdb-badge color="green">Sales <mdb-icon fas icon="arrow-circle-up"></mdb-icon></mdb-badge>
</h5>
</div>
.ts:
percent = 56;
ngAfterViewInit() {
setTimeout(() => {
this.percent = 20;
console.log('first change');
setTimeout(() => {
this.percent = 70;
console.log('second change');
}, 4000);
}, 3000);
}
Could you please check, if your console throws you any errors? Also, the code of your not working example would be helpful too.
Best Regards,
Damian
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- ForumUser: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: 7.5.4
- Device: Desktop
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No