简体   繁体   English

获取图表系列的颜色

[英]Get color of a chart series

I need to get the color of a series that is set by smart lables, I want to make a cell in a DGV the same color. 我需要获得由智能标签设置的系列的颜色,我想要使DGV中的单元格具有相同的颜色。

Dim chtColor(50) As Color

For Each Cur In MCurves
    PTang = EstCurve(Cur, BladeAngle, HRfan)

    Me.ChtCurves.Series.Add(Cur.ToString)
    Me.ChtCurves.Series(Cur.ToString).ChartType = DataVisualization.Charting.SeriesChartType.Spline
    Me.ChtCurves.ChartAreas(0).AxisX.LabelStyle.Format = "#.###"
    chtColor(i) = Me.ChtCurves.Series(Cur.ToString).Color 

The function Me.ChtCurves.Series(Cur.ToString).Color is returning a list of Colors and not the Series color. Me.ChtCurves.Series(Cur.ToString).Color函数返回的是颜色列表,而不是系列颜色。

If you are not explicitly setting a series color and want to retrieve the default assigned color, then you must call Chart.ApplyPaletteColors() . 如果没有显式设置系列颜色,并且想要检索默认的分配颜色,则必须调用Chart.ApplyPaletteColors()

Modify your code to call this method after adding the Series to the chart's Series collection 将系列添加到图表的系列集合后,修改代码以调用此方法

Me.ChtCurves.Series.Add(Cur.ToString)
Me.ChtCurves.Series(Cur.ToString).ChartType = DataVisualization.Charting.SeriesChartType.Spline
Me.ChtCurves.ChartAreas(0).AxisX.LabelStyle.Format = "#.###"

Me.ChtCurves.ApplyPaletteColors() ' this will allow you to retrieve the default color

chtColor(i) = Me.ChtCurves.Series(Cur.ToString).Color 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM