2014-12-24 2 views
0

오류가 없지만 점에 선을 작성하지 않습니다. 그래프에는 4 점이 있지만 라인은 없습니다.내 C# 차트에 선을 만들 수 없습니다.

private void button4_Click(object sender, EventArgs e) 
    { 
     int x1 = Convert.ToInt16(textBox1.Text); 
     int x2 = Convert.ToInt16(textBox2.Text); 
     int x3 = Convert.ToInt16(textBox3.Text); 
     int x4 = Convert.ToInt16(textBox4.Text); 

     int y1 = Convert.ToInt16(textBox1.Text); 
     int y2 = Convert.ToInt16(textBox2.Text); 
     int y3 = Convert.ToInt16(textBox3.Text); 
     int y4 = Convert.ToInt16(textBox4.Text); 
     x1 = 15; x2 = 19; x3 = 24; x4 = 29; 
     this.chart1.Series["HR"].Points.AddXY(x1, y1); 
     this.chart1.Series["HR"].Points.AddXY(x2, y2); 
     this.chart1.Series["HR"].Points.AddXY(x3, y3); 
     this.chart1.Series["HR"].Points.AddXY(x4, y4); 
    } 

    public void DrawlinePoint(PaintEventArgs e) 
    { 
     //Create pen. 
     Pen blackPen = new Pen(Color.Black,3); 
     // Create coordinates of points that define line. 
     int x1 = 11; 
     int y1 = 0; 
     int x4 = 37; 
     int y4 = 220; 
     //DrawLine to screen. 
     e.Graphics.DrawLine(blackPen, x1,y1,x4, y4); 
    } 
+0

도표를 해결하는 데 도움주세요 – jay

답변

0

여기에서 DrawlinePoint 방법을 호출합니까? PointEventArgs 매개 변수로 판단하면 Paint 이벤트에서 수행해야합니다. 차트 Paint 이벤트에 이벤트 처리기를 추가합니까? 더 다음 폼의 생성자에 추가 할 수 있습니다 경우 당신은 닷넷 3.5 이상을 사용하지 않을 경우, 보조 노트로 (

public Form1() 
{ 
    InitializeComponent(); 
    this.chart1.Paint += (sender, args) => this.DrawlinePoint(args); 
} 

당신은 표준 이벤트 처리기에 람다를 변경해야 할 것 .)

+0

그려진 선 (x1, y1) & (x4, y4)의 80 %를 계산하고 싶습니다. 계산 방법을 도와 줄 수 있습니까? @PiotWlkowski – jay

+0

WinForms 또는 프로그래밍 전반에 그리기와 관련이 없으므로 조금 다른 문제입니다. 선의 길이가 원래 길이의 80 %가되도록 하시겠습니까? 같은 위치에서 시작하지만 길이가 80 % 더 짧기를 원하십니까? 그렇다면 x4와 y4의 80 % 값을 계산하십시오. 'x4 = x4 * 0.8' 및'y4 = y4 * 0.8'. 그것은 순진한 해결책이지만 더 정교한 것도 똑같이 달성하기 쉽습니다. 당신을 위해 세부 사항을 알아내는 것을 떠날 것입니다. – PiotrWolkowski

관련 문제