Chart not setting color to points

Hello.
I'm creating a Bar chart and I want that every bar has a specific color, in order to do this, I'm setting the colors in js with method Create, but the chart still showing the default color value. Here is my code and the chart that the program is showing:

And js code:
but the chart still has the same default color:

Coult you help me? I don't know what's hapening
Thanks

P.D:
If I remove the redraw method then the chart is showing fine but I need to resize the window in order to get the corrects colors, and I want always showing like this.


3 Replies

DD Dharanidharan Dharmasivam Syncfusion Team March 29, 2018 12:33 PM UTC

Hi Neider, 

Thanks for using Syncfusion products. 

We have analyzed your query. Your requirement can be achieved by using the preRender event of chart. Here, you no need to take instance of chart and refresh it. In the preRender event you can able to get the chart properties and you can bind the required color to each point in the series. Find the code snippet below to achieve this. 

ASP.NET Core: 

<ej-chart pre-render="chartPreRender"> 
</ej-chart> 
 
function chartPreRender(sender) { 
        var colors = @Html.Raw(Json.Serialize(ViewBag.palette)); 
        for (var i = 0; i < colors.length; i++) 
            sender.model.series[0].points[i].fill = colors[i]; 
    } 


Screenshot: 
 
Sample for reference can be find from below link. 

Kindly revert us, if you have any concerns. 

Thanks, 
Dharani.


NE Neider April 2, 2018 03:15 PM UTC

It works!

Thanks :)


BP Baby Palanidurai Syncfusion Team April 3, 2018 04:20 AM UTC

Hi Neider, 

Thanks for your update, 

Please let us know if you need any further assistance on this. 

Regards, 
baby 


Loader.
Up arrow icon