How can I align the innerPlots?

风格不统一 提交于 2019-12-20 05:39:13

问题


I have 2 charts: chart1 and chart2.

I want both charts to have same innerPlotSize and location.

But chart1 has a secondary yaxis.

This does NOT work:

chart2.ChartAreas[0].AlignWithChartArea = chart1.ChartAreas[0].Name;
chart2.ChartAreas[0].AlignmentStyle = AreaAlignmentStyles.PlotPosition;
chart2.ChartAreas[0].AlignmentOrientation = AreaAlignmentOrientations.Vertical;

回答1:


This will align the InnerPlotPositions of two Charts:

    // align the controls:
    yourChart1.Left = yourChart2.Left;
    yourChart1.Size = yourChart2.Size;


    // get the numbers of the current innerplotpositions
    RectangleF ri1 = yourChart1.ChartAreas[0].InnerPlotPosition.ToRectangleF();
    RectangleF ri2 = yourChart2.ChartAreas[0].InnerPlotPosition.ToRectangleF();

    if (ri1.Width < ri2.Width)
    {
        yourChart2.ChartAreas[0].InnerPlotPosition =
            new ElementPosition(ri1.Left, ri2.Top, ri1.Width, ri2.Height);
    }
    else 
    {
        yourChart1.ChartAreas[0].InnerPlotPosition =
            new ElementPosition(ri2.Left, ri1.Top, ri2.Width, ri1.Height);
    }

Before and after:



来源:https://stackoverflow.com/questions/37567374/how-can-i-align-the-innerplots

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!