2017-04-10 3 views
1

차트 컨트롤을 System.Windows.Forms.DataVisualization.Charting에서 사용합니다. ChartType = SeriesChartType.Radar의 경우, 방사형 선이 전경으로 그려집니다. 이 줄을 배경으로 옮기는 법.차트 컨트롤 - ChartType 레이다의 모양

private void Form1_Load(object sender, EventArgs e) 
    { 

     chart1.ChartAreas.Clear(); 
     chart1.Series.Clear(); 
     ChartArea area = chart1.ChartAreas.Add("NewArea"); 
     Series serie1 = chart1.Series.Add("NewSerie1"); 
     serie1.ChartArea = "NewArea"; 
     serie1.ChartType = SeriesChartType.Radar; 
     area.AxisY.LineColor = Color.Red; 
     area.AxisY.LineWidth = 1; 

     for (Int32 j = 0; j <= 72; j++) 
     { 
      serie1.Points.AddXY(5 * j, 5 + j % 9); 
     } 

    } 

enter image description here

+0

[1] : https://i.stack.imgur.com/u2HIM.png – jdkern

+0

예제 그림에서 빨간색 선은 파란색 모양으로 숨겨져 있어야합니다. – jdkern

+0

업데이트 된 답변보기 – TaW

답변

0

당신은 정말 할 수 없습니다. 그러나 두 가지 해결 방법이 있습니다.

  • 사용자가 직접 레이더 영역을 그릴 수 있으므로 눈금 선을 덮을 수 있습니다. 쉬운 일은 아니지만 가능합니다. 그 몇 가지 힌트는 here을 참조하십시오 ..!

  • 당신은 반투명 눈금 선을 만들 수 있습니다 Color.FromArgb(64, Color.Red);

나는 Radar 차트에 그리기는 x로 특히, 실제로 Polar 버전과 약간 다른 것으로 나타났습니다 더 정밀한 점검에

업데이트

,462 : -values ​​정말 여기에 아무것도 의미하지 않는다 .. 그래서 여기

하는 예입니다 63,210

이 도면은 PostPaint로 수행됩니다

private void chart1_PostPaint(object sender, ChartPaintEventArgs e) 
{ 
    Graphics g = e.ChartGraphics.Graphics; 
    ChartArea ca = chart1.ChartAreas[0]; 
    Series s0 = chart1.Series[0]; 

    List<PointF> points = new List<PointF>(); 

    for (int i = 0; i < s0.Points.Count; i++) 
     points.Add(RadarValueToPixelPosition(s0, i, chart1, ca)); 

    g.FillPolygon(Brushes.LightSalmon, points.ToArray()); 
} 

좌표는 여기에 계산됩니다 그래서 우리는 내부 플롯 영역의 크기를 알 필요가

PointF RadarValueToPixelPosition(Series s, int index, Chart chart, ChartArea ca) 
{ 
    RectangleF ipp = InnerPlotPositionClientRectangle(chart, ca); 

    float phi = (float)(360f/s.Points.Count * index - 90 ); 
    float rad = (float)(phi * Math.PI/180f); 
    DataPoint dp = s.Points[index]; 

    float yMax = (float)ca.AxisY.Maximum; 
    float yMin = (float)ca.AxisY.Minimum; 
    float radius = ipp.Width/2f; 
    float len = (float)(dp.YValues[0] - yMin)/(yMax - yMin); 
    PointF C = new PointF(ipp.X + ipp.Width/2f, ipp.Y + ipp.Height/2f); 

    float xx = (float)(Math.Cos(rad) * radius * len); 
    float yy = (float)(Math.Sin(rad) * radius * len); 
    return new PointF(C.X + xx, C.Y + yy); 
} 

가하려면 :

RectangleF InnerPlotPositionClientRectangle(Chart chart, ChartArea CA) 
{ 
    RectangleF IPP = CA.InnerPlotPosition.ToRectangleF(); 
    RectangleF CArp = ChartAreaClientRectangle(chart, CA); 

    float pw = CArp.Width/100f; 
    float ph = CArp.Height/100f; 

    return new RectangleF(CArp.X + pw * IPP.X, CArp.Y + ph * IPP.Y, 
          pw * IPP.Width, ph * IPP.Height); 
} 

..이 크기는 ChartArea : 012에 따라 다릅니다.

RectangleF ChartAreaClientRectangle(Chart chart, ChartArea CA) 
{ 
    RectangleF CAR = CA.Position.ToRectangleF(); 
    float pw = chart.ClientSize.Width/100f; 
    float ph = chart.ClientSize.Height/100f; 
    return new RectangleF(pw * CAR.X, ph * CAR.Y, pw * CAR.Width, ph * CAR.Height); 
} 

도면에는 단 하나의 색상 만 사용됩니다. DataPoints에 다양한 색상이있는 경우 코드를 적용하여 다각형 또는 삼각형을 그릴 수 있습니다.

+0

감사합니다. 이것은 좋은 해결책입니다. 아마도 더 간단한 해결책이 없을 수도 있습니다. – jdkern