-1

[Chart I currently Have[1]

I have a Chart like this, It's not finished yet but I need to add this image to the left of the Chart.enter image description here

The chart is a Chart control from C# and the Second Image is a .png . How can I go about putting the image on the chart? The Chart is made on a .aspx page and is returned as an Image to be shown on a report so I need to be able to Return the Chart with the image on it as an Image.

Thanks in Advance!

Gustavo Jose
  • 45
  • 1
  • 2
  • 12

1 Answers1

1

Two ways..:

In order to place it correctly you will need to know exactly what you want.

enter image description here

Here is the example code to produce the above image:

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);

Chart coordinates are tricky.

Note that the Height and Y are in axis value coordinates since I have associated the Annotation with the Y-Axis as I also turned off IsSizeAlwaysRelative.

By default Annotatons are in relative coordinates, ie percentages of the respective containers. The horizontal numbers still are relative, so the 3 means 3% of the chart's width and the X = 0 positions the Annotation at the left egde..


Second way:

  • To place an image inside the plot area but below all gridlines and points you can use a StripLine instead of the Annotation. See here.

Example:

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);

enter image description here

Note that StripLines are in axis value coordinates!

The image should be added to the Chart.Images as a NamedImage.. When you do a chart.SaveImage the annotation or the stripline will be included..

TaW
  • 53,122
  • 8
  • 69
  • 111