17

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.

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
Ozzah
  • 10,631
  • 16
  • 77
  • 116

2 Answers2

35

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

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
  • 4
    Thanks! Who'd have thunk that what should have been called Series.LineDashStyle is actually called Series.BorderDashStyle! – Ozzah Feb 16 '11 at 02:41
  • why can't I use BorderDashStyle? I have `System.Windows.Forms.DataVisualization` added to the project – Mihai Bratulescu Jun 04 '14 at 10:22
5

This changes slightly with Visual Studio 2010's version of chart control:

this.chart1.Series["Data1"].BorderDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;

Kunklemeyer
  • 51
  • 1
  • 2
  • 1
    Note that [`Chart.Series[string name]`](http://msdn.microsoft.com/en-us/library/dd456421) is only a complementary indexer. [`Chart.Series[int index]`](http://msdn.microsoft.com/en-us/library/ms132434) remains available, so Chris's answer is completely valid in _.NET 4_ as well. – Anders Gustafsson Aug 13 '12 at 08:38
  • why am I not seeing `BorderDashStyle `? – Mihai Bratulescu May 20 '14 at 11:04
  • Is there any way of shortening `System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash`? – Ricky Robinson Nov 04 '14 at 09:44
  • 1
    If you put `using System.Windows.Forms.DataVisualization.Charting;` at the top of the .cs file, you can then shorten it to `ChartDashStyle.Dash`. – sstteevvee Nov 23 '14 at 11:53