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.

Tue Jan 07, 2020 3:16 am

I have created a bar chart,and i want to change the axis's color to red,I have tryed "chart.PrimaryCategoryAxis.Border.Color = Color.Red",but it not work,what can i do ?
Code: Select all
Workbook wb = new Workbook();
            wb.Version = ExcelVersion.Version2013;
            Worksheet ws = wb.Worksheets[0];

            ws.Range["A2"].Text = "cat1";
            ws.Range["A3"].Text = "cat 2";
            ws.Range["A4"].Text = "cat 3";
            ws.Range["A5"].Text = "cat 4";
            ws.Range["B1"].Text = "series1";
            ws.Range["B1"].Style.Font.IsBold = true;
            ws.Range["B2"].NumberValue = -98;
            ws.Range["B3"].NumberValue = -95;
            ws.Range["B4"].NumberValue = -91;
            ws.Range["B5"].NumberValue = -89;

            ws.Range["C1"].Text = "series2";
            ws.Range["C1"].Style.Font.IsBold = true;
            ws.Range["C2"].NumberValue = 43.81;
            ws.Range["C3"].NumberValue = 88.90;
            ws.Range["C4"].NumberValue = 38.07;
            ws.Range["C5"].NumberValue = 51.36;

            ws.Range["D1"].Text = "value1";
            ws.Range["D1"].Style.Font.IsBold = true;
            ws.Range["D2"].NumberValue = 98;
            ws.Range["D3"].NumberValue = 95;
            ws.Range["D4"].NumberValue = 91;
            ws.Range["D5"].NumberValue = 89;

            ws.Range["E1"].Text = "value2";
            ws.Range["E1"].Style.Font.IsBold = true;
            ws.Range["E2"].NumberValue = 43.81;
            ws.Range["E3"].NumberValue = 88.90;
            ws.Range["E4"].NumberValue = 38.07;
            ws.Range["E5"].NumberValue = 51.36;

            ws.Range["F1"].Text = "lable1";
            ws.Range["F1"].Style.Font.IsBold = true;
            ws.Range["F2"].Text = "98分";
            ws.Range["F3"].Text = "95分";
            ws.Range["F4"].Text = "91分";
            ws.Range["F5"].Text = "89分";

            ws.Range["G1"].Text = "lable2";
            ws.Range["G1"].Style.Font.IsBold = true;
            ws.Range["G2"].Text = "43.81%";
            ws.Range["G3"].Text = "88.90%";
            ws.Range["G4"].Text = "38.07%";
            ws.Range["G5"].Text = "51.36%";

            //ws.SetRowHeight(1, 40);

            Chart chart = ws.Charts.Add(ExcelChartType.BarClustered);


            chart.DataRange = ws.Range["A1:C5"];
            chart.SeriesDataFromRange = false;
            //chart.PrimaryValueAxis.HasMajorGridLines = false;

            chart.ChartArea.Border.Pattern = ChartLinePatternType.None;
            chart.PlotArea.Border.Pattern = ChartLinePatternType.None;
            chart.PlotArea.Fill.FillType = ShapeFillType.SolidColor;
            chart.PlotArea.Fill.BackColor = Color.White;
            chart.PlotArea.Fill.ForeColor = Color.White;

            chart.PrimaryValueAxis.HasMajorGridLines = false;
            chart.PrimaryValueAxis.Visible = false;

            chart.PrimaryCategoryAxis.Visible = true;
            chart.PrimaryCategoryAxis.HasMajorGridLines = false;
            chart.PrimaryCategoryAxis.TickLabelPosition = TickLabelPositionType.TickLabelPositionLow;
            chart.PrimaryCategoryAxis.MajorTickMark = TickMarkType.TickMarkNone;
            chart.PrimaryCategoryAxis.Border.Color = Color.Red;


            ChartSerie series1 = chart.Series[0];

            series1.Format.LineProperties.Pattern = ChartLinePatternType.Solid;
            var color = colors[0];
            series1.Format.ForeGroundColor = System.Drawing.Color.FromArgb(color[0], color[1], color[2]);
            series1.Format.Options.GapWidth = 100;
            series1.Format.Options.Overlap = 100;
            series1.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;

            chart.Series[0].DataPoints.DefaultDataPoint.DataLabels.ValueFromCell = ws.Range["F2:F5"];
            series1.DataPoints.DefaultDataPoint.DataLabels.Position = DataLabelPositionType.Inside;

            ChartSerie series2 = chart.Series[1];
            color = colors[1];
            series2.Format.ForeGroundColor = System.Drawing.Color.FromArgb(color[0], color[1], color[2]);
            series2.Format.Options.GapWidth = 100;
            series2.Format.Options.Overlap = 100;
            series2.DataPoints.DefaultDataPoint.DataLabels.HasValue = true;
            series2.DataPoints.DefaultDataPoint.DataLabels.ValueFromCell = ws.Range[$"G2:G5"];
            series2.DataPoints.DefaultDataPoint.DataLabels.Position = DataLabelPositionType.Inside;

            chart.ChartTitle = string.Empty;
            chart.ChartTitleArea.Text = "";
            chart.Legend.Position = LegendPositionType.Top;

            wb.SaveToFile(excelFile, ExcelVersion.Version2010);

standheo
 
Posts: 24
Joined: Mon Oct 08, 2018 11:13 am

Tue Jan 07, 2020 6:31 am

Hi,

Thanks for your inquiry.
Please try the code below to set the font color of the primary category axis in the chart to red.
Code: Select all
chart.PrimaryCategoryAxis.Font.Color = Color.Red;

If the code couldn't solve your issue, please offer us your desired result file for further investigation.
You could upload it here or send us(support@e-iceblue.com) via email.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Jan 08, 2020 1:36 am

no,what i want is not to set the font to red,but the primaryCategoryAxis border't color
Attachments
b2.png
b2.png (8.36 KiB) Viewed 1807 times
b1.png
ms-excel chart setting
b1.png (38.75 KiB) Viewed 1807 times
both.png
both.png (9.7 KiB) Viewed 1807 times

standheo
 
Posts: 24
Joined: Mon Oct 08, 2018 11:13 am

Wed Jan 08, 2020 5:58 am

Hi,

Thanks for your reply.
Sorry that I misunderstood your meaning last time. Please try the code below to set the border color of the primary category axis in the chart to red.
Code: Select all
            chart.PrimaryCategoryAxis.FrameFormat.Border.Color = Color.Red;

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Wed Jan 08, 2020 7:20 am

this is what i want,thank you very much :D :D

standheo
 
Posts: 24
Joined: Mon Oct 08, 2018 11:13 am

Wed Jan 08, 2020 7:54 am

Hi,

Thanks for your feedback.
Any question, welcome to contact us.

Best wishes,
Amber
E-iceblue support team
User avatar

Amber.Gu
 
Posts: 525
Joined: Tue Jun 04, 2019 3:16 am

Return to Spire.XLS