Spire.XLS for .NET is a professional Excel .NET library that can be used to any type of .NET( C#, VB.NET, ASP.NET, .NET Core) application and Java (J2SE and J2EE) application.

Thu Dec 20, 2018 8:28 am

Hey,
i want to build an column or barchart with different colors per bar is there a way to colorize each bar.

Semjasa
 
Posts: 22
Joined: Wed Dec 19, 2018 11:50 am

Thu Dec 20, 2018 8:54 am

Hi,

Thanks for your inquiry.
Please refer to following code:
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile(@"F:\sample.xlsx");
            Worksheet sheet = workbook.Worksheets[0];
            //add chart
            var chart = sheet.Charts.Add(ExcelChartType.ColumnClustered);
            //set the data range
            chart.DataRange = sheet.Range["A1:B2"];
            chart.SeriesDataFromRange = true;

            //set the different color for each bar/datapoint
            chart.Series[0].DataPoints[0].DataFormat.Fill.ForeColor = Color.Red;
            chart.Series[0].DataPoints[1].DataFormat.Fill.ForeColor = Color.Yellow;
            chart.Series[1].DataPoints[0].DataFormat.Fill.ForeColor = Color.Blue;
            chart.Series[1].DataPoints[1].DataFormat.Fill.ForeColor = Color.SkyBlue;

            workbook.SaveToFile("15944.xlsx", ExcelVersion.Version2010);

Any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3067
Joined: Tue Sep 06, 2016 8:30 am

Tue Dec 25, 2018 6:20 am

Hi,

Hope you are doing well.
Does the code I provided help you solve your issue? Could you please give us some feedback at your convenience?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3067
Joined: Tue Sep 06, 2016 8:30 am

Tue Jan 08, 2019 9:51 am

Sorry for this late post.

THX this works amazing

Thomas

Semjasa
 
Posts: 22
Joined: Wed Dec 19, 2018 11:50 am

Tue Jan 08, 2019 9:53 am

Hi,

Thank you for your feedback!
Just feel free to contact us if you need any assistance! :D

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Return to Spire.XLS