We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Cannot set Aspose Cells Series color

I tried the following but still, the color of the series doesn’t change

chart1.NSeries[1].Area.BackgroundColor = Color.Red;
chart1.NSeries[1].Area.ForegroundColor = Color.Red;

Workbook workbook = new Workbook();

        // Obtaining the reference of the first worksheet
        Worksheet worksheet = workbook.Worksheets[0];

        worksheet.Cells.ImportArray(test, 0, 10, true);

        // Adding sample values to cells
        worksheet.Cells["A1"].PutValue("Category1");
        worksheet.Cells["A2"].PutValue("Category2");
        worksheet.Cells["A3"].PutValue("Category3");
        worksheet.Cells["A4"].PutValue("Category4");

        worksheet.Cells["B1"].PutValue(4.3);
        worksheet.Cells["B2"].PutValue(2.5);
        worksheet.Cells["B3"].PutValue(3.50);
        worksheet.Cells["B4"].PutValue(4.50);

        worksheet.Cells["C1"].PutValue(4);
        worksheet.Cells["C2"].PutValue(4);
        worksheet.Cells["C3"].PutValue(4);
        worksheet.Cells["C4"].PutValue(4);
        // Adding a chart to the worksheet
        int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Column, 5, 0, 15, 5);

        // Accessing the instance of the newly added chart
        Aspose.Cells.Charts.Chart chart1 = worksheet.Charts[chartIndex];

        // Setting chart data source as the range  "A1:C4"
        chart1.SetChartDataRange("A1:C4", true);
        chart1.Style = 2;
        chart1.ShowLegend = false;
        chart1.ChartArea.Border.Color = Color.FromArgb(255, 217, 217, 217);
        chart1.ChartArea.Area.Formatting = Aspose.Cells.Charts.FormattingType.Custom;
        chart1.PlotArea.Area.Formatting = Aspose.Cells.Charts.FormattingType.None;
        chart1.PlotArea.Border.IsVisible = false;
        
        chart1.CategoryAxis.TickLabels.Font.Name = "Calibri";
        chart1.CategoryAxis.TickLabels.Font.Size = 10;
        chart1.CategoryAxis.Title.Text = "Rank";
        chart1.CategoryAxis.Title.Font.IsBold = true;
        chart1.CategoryAxis.AxisLine.IsVisible = false;


        chart1.ValueAxis.Title.Text = "Median Number of Days";
        chart1.ValueAxis.Title.Font.IsBold = true;
        chart1.ValueAxis.TickLabels.Font.Name = "Calibri";
        chart1.ValueAxis.TickLabels.Font.Size = 10;
        chart1.ValueAxis.AxisLine.IsVisible = false;
        chart1.ValueAxis.MajorGridLines.ThemeColor = new ThemeColor(ThemeColorType.Text1, 0.85);

        chart1.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;
        chart1.NSeries[1].Area.BackgroundColor = Color.Red;
        chart1.NSeries[1].Area.ForegroundColor = Color.Red;

        workbook.Save("../../../output.xls");

image.png (5.2 KB)

@mhore1522,

Please change the following lines of code:

chart1.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;
chart1.NSeries[1].Area.BackgroundColor = Color.Red;
chart1.NSeries[1].Area.ForegroundColor = Color.Red;

to:

chart1.NSeries[1].Type = Aspose.Cells.Charts.ChartType.Line;
chart1.NSeries[1].Border.Color = Color.Red;

Hope, this helps a bit.