Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.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# Winform MsChart次轴和带状线_C#_Winforms_Mschart - Fatal编程技术网

C# Winform MsChart次轴和带状线

C# Winform MsChart次轴和带状线,c#,winforms,mschart,C#,Winforms,Mschart,我对Winform中绘制的MSChart有几个问题 我无法获得图表右侧显示的Y2轴值,这应该是默认值-与此类似 带状线无法绘制,并且 是否可以将轴Y1和Y2的零值对齐 谢谢你的帮助 ChartArea TestChartArea = new ChartArea(); public void CreateChartArea() { TestChartArea.Name = "TestChartArea"; TestC

我对Winform中绘制的MSChart有几个问题

  • 我无法获得图表右侧显示的Y2轴值,这应该是默认值-与此类似

  • 带状线无法绘制,并且

  • 是否可以将轴Y1和Y2的零值对齐

    谢谢你的帮助

        ChartArea TestChartArea = new ChartArea();
    
        public void CreateChartArea()
        {
            TestChartArea.Name = "TestChartArea";
            TestChartArea.BackColor = Color.LightGreen;
            TestChartArea.Position = new ElementPosition { Height = 100, Width = 80, X = 2, Y = 5 };
            //TestChartArea.Position = new ElementPosition { Auto = true };
            TestChartArea.AxisY = new Axis
            {
                Enabled = AxisEnabled.True,
                IsLabelAutoFit = true,
                IsMarginVisible = true,
                LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
                LineColor = Color.Black,
                MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
                MajorTickMark = new TickMark { LineColor = Color.Black }
            };
    
            TestChartArea.AxisY2 = new Axis
            {
                Enabled = AxisEnabled.True,
                IsLabelAutoFit = true,
                IsMarginVisible = true,
                LabelStyle = new LabelStyle { Format = "P2", ForeColor = Color.DarkBlue, Font = new Font("Arial", 10, FontStyle.Regular) },
                LineColor = Color.Transparent,
                MajorGrid = new Grid { LineColor = Color.Yellow, LineDashStyle = ChartDashStyle.Solid },
                MajorTickMark = new TickMark { LineColor = Color.Blue }
    
            };
    
            TestChartArea.AxisX = new Axis
            {
                Enabled = AxisEnabled.True,
                Crossing = 0,
                LineWidth = 1,
                IsLabelAutoFit = true,
                IsMarginVisible = false,
                LabelStyle = new LabelStyle {  Angle=-45,Format = "N0", ForeColor = Color.Black, Font = new Font("Arial", 8, FontStyle.Regular) },
                LineColor = Color.Black,
                MajorGrid = new Grid { LineColor = Color.White, LineDashStyle = ChartDashStyle.Solid },
                MajorTickMark = new TickMark { LineColor = Color.LightGray, Size = 4.0f },
                Name="Spot"
    
            };
        }
    
        public void PlotChart()
        {
            int[] Xseries = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            double[] AXJO = { 0.0025, 0.0015, -0.001, 0.002, 0.0045, -0.002, -0.003, 0.0001, -0.004, -0.0075 };
            double[] ES = { 0.0020, 0.0010, -0.0005, 0.003, 0.0025, -0.001, -0.0015, 0.0005, -0.0032, -0.006 };
            double[] Diff = new double[10];
    
            // pair return
            for (int i = 0; i < 10; i++)
            {
                Diff[i] = AXJO[i] - ES[i];
            }
    
            TestChart.BackColor = Color.LightGoldenrodYellow;
            TestChart.BackSecondaryColor = Color.LightBlue;
    
            if (TestChart.Series.IsUniqueName("AXJO"))
            {
                TestChart.Series.Add("AXJO");
                TestChart.Series["AXJO"].YAxisType = AxisType.Primary;
                TestChart.Series["AXJO"].Color = Color.Green;
                TestChart.Series["AXJO"].ChartType = SeriesChartType.Line;
                TestChart.Series["AXJO"].Points.DataBindXY(Xseries, AXJO);
                TestChart.Series["AXJO"].ChartArea = "TestChartArea";
            }
    
            if (TestChart.Series.IsUniqueName("ES"))
            {
                TestChart.Series.Add("ES");
                TestChart.Series["ES"].YAxisType = AxisType.Primary;
                TestChart.Series["ES"].Color = Color.Red;
                TestChart.Series["ES"].ChartType = SeriesChartType.Line;
                TestChart.Series["ES"].Points.DataBindXY(Xseries, ES);
                TestChart.Series["ES"].ChartArea = "TestChartArea";
            }
    
            if (TestChart.Series.IsUniqueName("Diff"))
            {
                TestChart.Series.Add("Diff");
                TestChart.Series["Diff"].YAxisType = AxisType.Secondary;
                TestChart.Series["Diff"].Color = Color.Blue;
                TestChart.Series["Diff"].ChartType = SeriesChartType.Line;
                TestChart.Series["Diff"].Points.DataBindXY(Xseries, Diff);
                TestChart.Series["Diff"].ChartArea = "TestChartArea";
            }
        }
    
        public void AddStripLine()
        {
            // add stripline at Diff=zero
            StripLine ZeroDiff = new StripLine();
            ZeroDiff.ForeColor = Color.Black;
            ZeroDiff.BackColor = Color.Black;
            ZeroDiff.StripWidth = 1;
            ZeroDiff.BorderWidth = 2;
            ZeroDiff.Interval = 0;
            ZeroDiff.IntervalOffset = 10;
            TestChart.ChartAreas["TestChartArea"].AxisY2.StripLines.Add(ZeroDiff);
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            PlotChart();
            AddStripLine();
        }
    }
    
    ChartArea TestChartArea=新建ChartArea();
    公共区域()
    {
    TestChartArea.Name=“TestChartArea”;
    TestChartArea.BackColor=Color.LightGreen;
    TestChartArea.Position=新元素Position{Height=100,Width=80,X=2,Y=5};
    //TestChartArea.Position=newElementPosition{Auto=true};
    TestChartArea.AxisY=新轴
    {
    Enabled=AxisEnabled.True,
    IsLabelAutoFit=真,
    Ismargin=true,
    LabelStyle=新LabelStyle{Format=“P2”,前景色=Color.DarkBlue,Font=新字体(“Arial”,10,FontStyle.Regular)},
    LineColor=颜色。黑色,
    MajorGrid=new Grid{LineColor=Color.White,LineDashStyle=ChartDashStyle.Solid},
    MajorTickMark=newtickmark{LineColor=Color.Black}
    };
    TestChartArea.AxisY2=新轴
    {
    Enabled=AxisEnabled.True,
    IsLabelAutoFit=真,
    Ismargin=true,
    LabelStyle=新LabelStyle{Format=“P2”,前景色=Color.DarkBlue,Font=新字体(“Arial”,10,FontStyle.Regular)},
    LineColor=颜色。透明,
    MajorGrid=new Grid{LineColor=Color.Yellow,LineDashStyle=ChartDashStyle.Solid},
    MajorTickMark=newtickmark{LineColor=Color.Blue}
    };
    TestChartArea.AxisX=新轴
    {
    Enabled=AxisEnabled.True,
    交叉=0,
    线宽=1,
    IsLabelAutoFit=真,
    IsMarginVisible=false,
    LabelStyle=新LabelStyle{Angle=-45,Format=“N0”,前景色=Color.Black,Font=新字体(“Arial”,8,FontStyle.Regular)},
    LineColor=颜色。黑色,
    MajorGrid=new Grid{LineColor=Color.White,LineDashStyle=ChartDashStyle.Solid},
    MajorTickMark=新勾号{LineColor=Color.LightGray,Size=4.0f},
    Name=“Spot”
    };
    }
    公共地图图()
    {
    int[]Xseries={1,2,3,4,5,6,7,8,9,10};
    双[]AXJO={0.0025,0.0015,-0.001,0.002,0.0045,-0.002,-0.003,0.0001,-0.004,-0.0075};
    双[]ES={0.0020,0.0010,-0.0005,0.003,0.0025,-0.001,-0.0015,0.0005,-0.0032,-0.006};
    double[]Diff=新的double[10];
    //成对返回
    对于(int i=0;i<10;i++)
    {
    Diff[i]=AXJO[i]-ES[i];
    }
    TestChart.BackColor=Color.LightGoldenrodYellow;
    TestChart.BackSecondaryColor=Color.LightBlue;
    if(TestChart.Series.IsUniqueName(“AXJO”))
    {
    TestChart.Series.Add(“AXJO”);
    TestChart.Series[“AXJO”].YAxisType=AxisType.Primary;
    TestChart.Series[“AXJO”].Color=Color.Green;
    TestChart.Series[“AXJO”].ChartType=serieChartType.Line;
    TestChart.Series[“AXJO”].Points.DataBindXY(Xseries,AXJO);
    TestChart.Series[“AXJO”].ChartArea=“TestChartArea”;
    }
    if(TestChart.Series.IsUniqueName(“ES”))
    {
    TestChart.Series.Add(“ES”);
    TestChart.Series[“ES”].YAxisType=AxisType.Primary;
    TestChart.Series[“ES”].Color=Color.Red;
    TestChart.Series[“ES”].ChartType=SerieChartType.Line;
    TestChart.Series[“ES”].Points.DataBindXY(Xseries,ES);
    TestChart.Series[“ES”].ChartArea=“TestChartArea”;
    }
    if(TestChart.Series.IsUniqueName(“Diff”))
    {
    测试图系列添加(“差异”);
    TestChart.Series[“Diff”].YAxisType=AxisType.Secondary;
    TestChart.Series[“Diff”].Color=Color.Blue;
    TestChart.Series[“Diff”].ChartType=serieChartType.Line;
    TestChart.Series[“Diff”].Points.DataBindXY(Xseries,Diff);
    TestChart.Series[“Diff”].ChartArea=“TestChartArea”;
    }
    }
    public void AddStripLine()
    {
    //在差异=零处添加带状线
    带状线ZeroDiff=新带状线();
    ZeroDiff.ForeColor=颜色为黑色;
    ZeroDiff.BackColor=颜色为黑色;
    ZeroDiff.StripWidth=1;
    ZeroDiff.BorderWidth=2;
    零差间隔=0;
    零差间隔偏移=10;
    TestChart.ChartAreas[“TestChartArea”].AxisY2.StripLines.Add(ZeroDiff);
    }
    私有无效按钮1\u单击(对象发送者,事件参数e)
    {
    绘图仪();
    AddStripLine();
    }
    }
    

  • 您通过将其
    交叉属性设置为
    0

    只需不设置它,将其保留为默认的
    double.NaN
    ,以便自动将其放置在右侧,即可解决此问题

    Crossing = double.NaN
    

    要使带状线显示,它需要在其轴的可见范围内开始。将其偏移10对于您的数据来说太过分了。。另外,将其变为黑色可能不是您想要的,除非您只想要一条细线,而不是彩色区域

    带状线的基本规则是:

    • Interval=0
      时,在
      IntervalOffset
      处仅显示一条带线,其宽度/高度为
      StripWidth
    • Interval>0
      显示许多条带状线时,这些带状线穿过整个轴;除非您有半色调,否则您需要确保
      StripWidth
      ,否则它们之间没有空格
    • 所有测量值均为轴值;可以使用
      StripWidthType