Back to Devexpress

How to: Change the Color of Series Points

windowsforms-120772-controls-and-libraries-spreadsheet-examples-charts-how-to-change-the-color-of-series-points.md

latest3.2 KB
Original Source

How to: Change the Color of Series Points

  • Oct 29, 2020
  • 2 minutes to read

This topic describes how to apply custom colors to series points.

Change the Color of Individual Data Points

To change a data point’s appearance, add a new item to the Series.CustomDataPoints collection with the index equal to the zero-based position of the modified data point in the series. Then, use the following members to specify the data point’s color:

csharp
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];

// Hide the chart's legend.
chart.Legend.Visible = false;

// Fill the third data point with red color.
chart.Series[0].CustomDataPoints.Add(2).Fill.SetSolidFill(Color.Red);
// Fill the sixth data point with green color.
chart.Series[0].CustomDataPoints.Add(5).Fill.SetSolidFill(Color.Green);
vb
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L15")

' Hide the chart's legend.
chart.Legend.Visible = False

' Fill the third data point with red color.
chart.Series(0).CustomDataPoints.Add(2).Fill.SetSolidFill(Color.Red)
' Fill the sixth data point with green color.
chart.Series(0).CustomDataPoints.Add(5).Fill.SetSolidFill(Color.Green)

Apply Different Colors to Same-Series Data Points

The following example shows how to use the ChartView.VaryColors property to apply a different color to each data marker in the series.

csharp
// Create a chart and specify its location.
Chart chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet["B2:C8"]);
chart.TopLeftCell = worksheet.Cells["F2"];
chart.BottomRightCell = worksheet.Cells["L15"];

// Specify that each data point in the series has a different color.
chart.Views[0].VaryColors = true;
// Hide the legend.
chart.Legend.Visible = false;
vb
' Create a chart and specify its location.
Dim chart As Chart = worksheet.Charts.Add(ChartType.ColumnClustered, worksheet("B2:C8"))
chart.TopLeftCell = worksheet.Cells("F2")
chart.BottomRightCell = worksheet.Cells("L15")

' Specify that each data point in the series has a different color.
chart.Views(0).VaryColors = True
' Hide the legend.
chart.Legend.Visible = False