Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Aug 06, 2020 4:31 pm

Is there a way to set each pie slice in a series to specific colors using FreeSpireXls C#?

I am working with your example Pie in C#, and I do not see an example on how to set slice colors programmatically.

Thanks

steveh54
 
Posts: 2
Joined: Thu Aug 06, 2020 4:26 pm

Thu Aug 06, 2020 4:44 pm

Found an answer in another similar post:
Code: Select all
ChartSerie sers = sheet.Charts[0].Series[0];
int datapoints=  sers.Values.Count;
for (int i = 0; i < datapoints; i++)
{
    switch (i.ToString())
    {
        case "0":
            sers.DataPoints[i].DataFormat.Fill.ForeColor = Color.Red;
            break;
        case "1":
            sers.DataPoints[i].DataFormat.Fill.ForeColor = Color.Yellow;
            break;
        case "2":
            sers.DataPoints[i].DataFormat.Fill.ForeColor = Color.Green;
            break;
        case "3":
            sers.DataPoints[i].DataFormat.Fill.ForeColor = Color.Blue;
            break;
        case "4":
            sers.DataPoints[i].DataFormat.Fill.ForeColor = Color.Black;
            break;
    }
}

steveh54
 
Posts: 2
Joined: Thu Aug 06, 2020 4:26 pm

Fri Aug 07, 2020 6:03 am

Hello,

Glad to hear that you have found the solution.
If you have any other question, just feel free to contact us.
Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.XLS