2016-06-27 1 views
0

C# 차트의 사용자 지정 레이블을 배경 이미지로 바꾸고 그 위에 레이블 텍스트를 쓰려고합니다.차트 사용자 지정 레이블에 대한 이미지 구성 방법

이미지 레이블 속성 & 텍스트를 사용해 보았습니다.하지만 그 둘은 서로 옆에 놓입니다.

이것이 가능합니까? 차트가 y 좌표를 전달할 수 있도록 내가 그려진 함수를 사용할 수 있습니까?

enter image description here enter image description here

감사

+0

당신은 당신이보고 싶어 무엇의 예를 보여줄 수 있습니까? 비트 맵과 텍스트를 결합하여 이미지를 동적으로 만들 수 있습니다. – TaW

답변

1

여기 차트 동적 이미지를 생성하는 예이다. 당신은 당신이 다른 텍스트와 다른 이름으로 필요에 따라 그들 중 많은 사람을 만들 것입니다 .. : 물론 스타일링의

Axis ax = chart.ChartAreas[0].AxisX; 
CustomLabel cl = new CustomLabel(); 
cl.FromPosition = chart.Series[0].Points[0].XValue; // some values, which will place 
cl.ToPosition = chart.Series[0].Points[1].XValue; // the cl between two points 
cl.Text = ""; // no text, please! 

cl.Image = "img01"; // this is our NamedImage 

ax.CustomLabels.Add(cl); // now we can add the CL 

:

Image img = Image.FromFile(someTemplateImage); 

// draw a text into it: 
using (Graphics G = Graphics.FromImage(img)) 
    G.DrawString("Hello", Font, Brushes.Blue, 1, 1); 
// add it to the chart images with a name: 
chart.Images.Add(new NamedImage("img01", img)); 

이제 우리는 우리의 이미지를 보여줍니다 사용자 지정 라벨을 만들 수 있습니다 글꼴 및 aligmnment에 그려진 문자열

이 그냥 하나의 이미지와 예와 단일cl입니다 .. 당신에게 달려 있습니다. 필요에 따라 이미지의 이름을 지정하고 텍스트를 추가하는 방법을 생각하고 싶을 것입니다.

이동할 수있는 예를 보려면 게시물을 참조하십시오. Here 많은 마커 이미지를 만듭니다. 플라이 및 here 마커 이미지는 히트 맵을 생성하는 데 사용됩니다. 여기

은 .. 축에 각 사용자 지정 라벨에 템플릿 이미지를 추가하는 adorner 기능입니다 :

public void AddornCLs(Chart chart, Axis axis, Image template, Font font, Color color) 
{ 
    Rectangle rect = new Rectangle(Point.Empty, template.Size); 
    TextFormatFlags format = TextFormatFlags.HorizontalCenter 
          | TextFormatFlags.VerticalCenter; 

    foreach(CustomLabel cl in axis.CustomLabels) 
    { 
     string text = cl.Text; 
     if (text == "") text = cl.Tag.ToString(); else cl.Tag = cl.Text; 
     cl.Text = ""; 
     if (cl.Name == "") cl.Name = axis.CustomLabels.IndexOf(cl).ToString("CL000"); 
     Image img = (Image)template.Clone(); 
     using (Graphics G = Graphics.FromImage(img)) 
      TextRenderer.DrawText(G, text, font, rect, color, format); 
     chart.Images.Add(new NamedImage(cl.Name, img)); 
     cl.Image = cl.Name; 
    } 
} 
+0

감사합니다. 도움이되었습니다. – Studley

+0

몇 가지 더 유용한 트릭 .. 내 업데이 트를 참조하십시오! – TaW

관련 문제