Teechart multiple axis creation

送分小仙女□ 提交于 2019-12-11 15:03:50

问题


I am new to C# programming. I am working in a firm, someone has completed some task and left with graph parts. Now i have to do this.

I am using steema chart in C#, I want to create chart with multiple axis on left side of the chart (y-axis) and comman x- axis for all. Each axis on lest side will be different axis lengths.

I have created six check boxes for different sensor, when i tick that box then regarding axis with default length should appear. I have created check box's but i am not able to set axis length and also i am not able to draw multiple axis.

I don't know this is the right way to ask? Please excuse me if i am wrong? if i haven't provided much information then please ask me i will do it.

I want to draw the type of chart as shown in the attached image. The X-axis(system time) is common for all series and Y-axis is different for each series. i have chek boxes for all series so when check box checked then that series Y-axis has to display with default axis range(for example min (0) and max (1000)).

Thanks in advance.


回答1:


Something very similar was discussed in the Steema Support forums some time ago. Give it a look here.

I post the same code here:

    int nSeries = 3;
    private void InitializeChart()
    {
        tChart1.Aspect.View3D = false;
        tChart1.Header.Visible = false;
        tChart1.Legend.Alignment = LegendAlignments.Bottom;
        for (int i = 0; i < nSeries; i++)
        {
            new Steema.TeeChart.Styles.Line(tChart1.Chart);
            tChart1.Axes.Custom.Add(new Steema.TeeChart.Axis(tChart1.Chart));
            tChart1[i].CustomVertAxis = tChart1.Axes.Custom[i];
            tChart1.Axes.Custom[i].AxisPen.Color = tChart1[i].Color;
            tChart1.Axes.Custom[i].Grid.Visible = false;
            tChart1.Axes.Custom[i].Title.Visible = true;
            tChart1.Axes.Custom[i].Title.Caption = "Series" + i.ToString();
            tChart1[i].FillSampleValues(20);
            tChart1.Axes.Custom[i].PositionUnits = PositionUnits.Pixels;
        }

        tChart1.Panel.MarginUnits = PanelMarginUnits.Pixels;
        tChart1.Draw();
        PlaceAxes(0, 0, 0, 0, 0);
        tChart1.Draw();
    }

    private void PlaceAxes(int nSeries, int NextXLeft, int NextXRight, int MargLeft, int MargRight)
    {
        const int extraPos = 12;
        const int extraMargin = 105;
        //Variable
        int MaxLabelsWidth;
        int lenghtTicks;
        int extraSpaceBetweenTitleAndLabels;
        if (tChart1[nSeries].Active)
        {
            MaxLabelsWidth = tChart1.Axes.Custom[nSeries].MaxLabelsWidth();
            lenghtTicks = tChart1.Axes.Custom[nSeries].Ticks.Length;
            extraSpaceBetweenTitleAndLabels = (tChart1.Axes.Custom[nSeries].Title.Width);//- tChart1.Axes.Custom[nSeries].MaxLabelsWidth());
            if (tChart1.Axes.Custom[nSeries].OtherSide)
            {
                tChart1.Axes.Custom[nSeries].RelativePosition = NextXRight;
                NextXRight = NextXRight - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                MargRight = MargRight + extraMargin;
            }

            else
            {
                tChart1.Axes.Custom[nSeries].RelativePosition = NextXLeft;
                NextXLeft = NextXLeft - (MaxLabelsWidth + lenghtTicks + extraSpaceBetweenTitleAndLabels + extraPos);
                MargLeft = MargLeft + extraMargin;
            }

            tChart1.Panel.MarginLeft = MargLeft;
            tChart1.Panel.MarginRight = MargRight;

            nSeries++;

            if (nSeries <= tChart1.Series.Count - 1)
            {
                PlaceAxes(nSeries, NextXLeft, NextXRight, MargLeft, MargRight);
            }
        }
    }


来源:https://stackoverflow.com/questions/14692012/teechart-multiple-axis-creation

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