windowsforms-120772-controls-and-libraries-spreadsheet-examples-charts-how-to-change-the-color-of-series-points.md
This topic describes how to apply custom colors to series 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:
// 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);
' 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)
The following example shows how to use the ChartView.VaryColors property to apply a different color to each data marker in the series.
// 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;
' 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