Drawing linear graph with primary and secondary axis y C #

I studied how to draw diagrams in C #. I have a specific requirement of drawing a chart with the axis of the a axis and the x axis and the second y axis. I tried using excel Interop but could not find a solution. I started working with the MSChart component, but nothing has been achieved. work with the

index lines branches 1 20 5 2 30 8 3 34 6 

I want to build indexes on the x axis and the scale for the rows on the left y axis and the scale for the branches on the right y axis.

I am using .net versions 2.0 and 3.5 if this helps

+7
source share
1 answer

When creating a series, set the YAxisType property to AxisType.Primary or AxisType.Secondary

  var lines = new Series("lines"); lines.ChartType = SeriesChartType.Line; lines.Points.Add(new DataPoint(1, 20)); lines.Points.Add(new DataPoint(2, 30)); lines.Points.Add(new DataPoint(3, 34)); lines.YAxisType = AxisType.Primary; chart1.Series.Add(lines); var branches = new Series("branches"); branches.ChartType = SeriesChartType.Line; branches.Points.Add(new DataPoint(1, 5)); branches.Points.Add(new DataPoint(2, 6)); branches.Points.Add(new DataPoint(3, 8)); branches.YAxisType = AxisType.Secondary; chart1.Series.Add(branches); 

The result is a chart that sounds like you. The example below is a little ugly, it has rows for primary and secondary y values, etc., but you can clear them the way you want by setting the properties of the chart control.

enter image description here

+11
source

All Articles