【问题标题】:drawing line graph with primary and secondary y axis c#绘制具有主要和次要y轴的折线图c#
【发布时间】:2012-07-31 05:45:08
【问题描述】:

我一直在研究用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# mschart excel-interop


    【解决方案1】:

    创建系列时,将YAxisType 属性设置为AxisType.PrimaryAxisType.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 值等的线,但你可以通过设置图表控件的属性来按照你想要的方式清理它。

    【讨论】:

    • 您设置哪些属性来对齐它们?
    • 正如@muzzlator 所问,什么属性可以使 Y 主轴和次轴在网格线上对齐?
    猜你喜欢
    • 2021-12-02
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多