C# dashed lines in chart series?

Ozzah picture Ozzah · Feb 16, 2011 · Viewed 31.3k times · Source

I'm using the Chart control from .net 4.0 in my C# WinForms app. I have two series' of data displayed as line graphs.

I'm graphing basically a supply and demand as a function of time. I want the demand to be a solid line of some colour, and the supply to be a dashed line of the same colour.

I can set the colour fine, but I can't find anywhere where I can set the line style to be dashed.

Answer

Chris Schmich picture Chris Schmich · Feb 16, 2011

See the DataPointCustomProperties.BorderDashStyle property. For example...

_chart.Series[1].Color = Color.Blue;

_chart.Series[0].Color = Color.Blue;
_chart.Series[0].BorderWidth = 3;
_chart.Series[0].BorderDashStyle = ChartDashStyle.Dash;

...gives me:

enter image description here