We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Get color assigned in chart

Hi,

In Doughnut chart, How can I get the color assigned to a specific value of serie?

Thanks

5 Replies

DD Dharanidharan Dharmasivam Syncfusion Team February 19, 2019 03:45 PM UTC

Hi Manolo, 
 
Greetings from Syncfusion.  
 
We have analyzed your requirement. You can get the color assigned to each point using the pointRender event. This event will be triggered for each point. Find the code snippet below to achieve this requirement. 
 
 
 
<ejs-accumulationchart (pointRender)='pointRender($event)' > 
    Other configurations 
 </ejs-accumulationchart> 
 
public pointRender(args: IAccPointRenderEventArgs): void { 
    console.log(args.fill) 
  } 
 
 
 
We have displayed the color in console window. You can change this with respect to your scenario. 
 
Thanks, 
Dharani. 
 
 



MC Manolo Capdevila February 22, 2019 08:55 AM UTC

Hi,

Sorry, I explain bad.

I need get each colour assigned in a serie. So, I can set this color in other labels.

But I can get access to pallete property

Thanks


KC Kalaimathi Chellaiah Syncfusion Team February 22, 2019 11:45 AM UTC

Hi Manolo, 

Thanks for using Syncfusion products. 

We have analyzed your query and prepared stackblitz sample for your requirement. By using ` textRender` event you can get current label’s series point color in event argument. 

Code Snippet: 

 
 



Kindly revert us back, If it is not your requirement. 

Regards, 
Kalai. 



MC Manolo Capdevila February 22, 2019 01:57 PM UTC

Hi,

It is not my requirement...

In your example, I need get, for example, the color assigned to "Labour" data.

So, in label out of the chart, I can set the same color.

Thanks


DD Dharanidharan Dharmasivam Syncfusion Team February 25, 2019 05:36 AM UTC

Hi Manolo, 
 
Thanks for the update. We have analyzed your requirement, and this can be achieved using pointRender event and textRender event. Using the point render event, we can get the color assigned to each point and using the textRender event, assign the colors to each data label. Find the code snippet below to achieve this. 
 
[donut.html] 
 
<ejs-accumulationchart pointRender)='pointRender($event)' (textRender)='textRender($event)'> 
</ejs-accumulationchart> 
 
 
[donut.component.ts] 
 
Declare a public variable to store the colors obtained in pointRender event 
public colorCollection = []; 
public pointRender(args: IAccPointRenderEventArgs): void {  
    this.colorCollection.push(args.fill)  
  }  
 
public textRender(args): void{ 
     Assigned the color obtained in point render event 
      args.font.color = this.colorCollection[this.count]; 
      this.count ++; 
 }; 
 
 
 
 
Screenshot: 
 
 
 
Thanks, 
Dharani. 


Loader.
Live Chat Icon For mobile
Up arrow icon