Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用主y轴和次y轴c绘制线图#_C#_Mschart_Excel Interop - Fatal编程技术网

C# 使用主y轴和次y轴c绘制线图#

C# 使用主y轴和次y轴c绘制线图#,c#,mschart,excel-interop,C#,Mschart,Excel Interop,我一直在研究用c#绘制图表的方法。我有一个特定的要求,即绘制一个带有y轴和x轴以及第二个y轴的图表。我曾尝试使用excel Interop,但没有找到解决方案。我已开始使用MSChart组件,但尚未获得任何数据。我正在使用的数据是 index lines branches 1 20 5 2 30 8 3 34 6 我想在x轴上绘制索引,在左y轴上绘制线的比例,在右y轴上绘制分支的比例 我使用的是.net版本2.0和3.5,如果这有助于创建系

我一直在研究用c#绘制图表的方法。我有一个特定的要求,即绘制一个带有y轴和x轴以及第二个y轴的图表。我曾尝试使用excel Interop,但没有找到解决方案。我已开始使用MSChart组件,但尚未获得任何数据。我正在使用的数据是

index lines branches
1      20     5
2      30     8
3      34     6
我想在x轴上绘制索引,在左y轴上绘制线的比例,在右y轴上绘制分支的比例


我使用的是.net版本2.0和3.5,如果这有助于创建系列,请将
YAxisType
属性设置为
AxisType.Primary
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);
这会产生一个这样的图表,听起来像你想要的。下面的示例有点难看,它有用于主y值和次y值的行,等等。但是您可以通过设置图表控件的属性,按照您想要的方式来清理它


您设置了哪些属性来对齐它们?正如@muzzlator所问的,哪些属性将使Y主轴和次轴在网格线上?