[英]How to Add an Image to a Chart
兩種方法:
為了正確放置它,您將需要確切地知道您想要什么。
這是產生以上圖像的示例代碼:
chart1.Images.Add(new NamedImage("gradient", Image.FromFile(yourImagePath)));
ImageAnnotation imgA = new ImageAnnotation();
imgA.Image = "gradient";
imgA.ImageWrapMode = ChartImageWrapMode.Scaled;
imgA.IsSizeAlwaysRelative = false;
imgA.AxisY = ay;
imgA.Y = ay.Minimum;
imgA.Height = ay.Maximum - ay.Minimum;
imgA.X = 0;
imgA.Width = 3;
chart1.Annotations.Add(imgA);
圖表坐標很棘手。
請注意,由於我已經將Annotation與Y軸相關聯,因此Height
和Y
在axis value coordinates
因為我還關閉了IsSizeAlwaysRelative
。
默認情況下, Annotatons
位於相對坐標中 ,即相應容器的百分比。 水平數字仍然是相對的,因此3
表示圖表寬度的3%
,並且X = 0
將Annotation
放置在左側的位置。
第二種方式:
例:
StripLine sl = new StripLine();
sl.IntervalOffset = -1;
sl.Interval = 0;
sl.StripWidth = 0.33;
sl.BorderWidth = 0;
sl.BackImage = "gradient";
sl.BackImageWrapMode = ChartImageWrapMode.Scaled;
ax.StripLines.Add(sl);
注意, StripLines
線在軸值坐標中!
圖像應被添加到Chart.Images
作為NamedImage
。當你做一個chart.SaveImage
注釋或帶狀線將被納入..
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.