Chart.SetBackgroundPicture(String) Method

Definition

Sets the background graphic for Chart control.

public:
 void SetBackgroundPicture(System::String ^ Filename);
public void SetBackgroundPicture (string Filename);
abstract member SetBackgroundPicture : string -> unit
Public Sub SetBackgroundPicture (Filename As String)

Parameters

Filename
String

The name of the graphic file.

Examples

The following code example creates a Chart and then uses the SetBackgroundPicture method to set the background of the chart to an image file.

private void ApplyNewBackground()
{
    this.Range["A1", "A5"].Value2 = 22;
    this.Range["B1", "B5"].Value2 = 55;

    Microsoft.Office.Tools.Excel.Chart chart1 =
        this.Controls.AddChart(this.Range["D2", "H12"], 
        "chart1");

    chart1.SetSourceData(this.Range["A1", "B5"], 
        Excel.XlRowCol.xlColumns);
    chart1.ChartType = Excel.XlChartType.xl3DColumn;

    string backgroundFilePath = @"c:\image1.jpg";

    if (System.IO.File.Exists(backgroundFilePath))
    {
        chart1.SetBackgroundPicture(@"c:\image1.jpg");
    }
    else
    {
        MessageBox.Show(@"The file image1.jpg does not exist at C:\");
    }
}
Private Sub ApplyNewBackground()
    Me.Range("A1", "A5").Value2 = 22
    Me.Range("B1", "B5").Value2 = 55

    Dim Chart1 As Microsoft.Office.Tools.Excel.Chart = _
        Me.Controls.AddChart(Me.Range("D2", "H12"), "Chart1")

    Chart1.SetSourceData(Me.Range("A1", "B5"), Excel.XlRowCol.xlColumns)
    Chart1.ChartType = Excel.XlChartType.xl3DColumn

    Dim backgroundFilePath As String = "c:\image1.jpg"

    If System.IO.File.Exists(backgroundFilePath) Then
        Chart1.SetBackgroundPicture("c:\image1.jpg")
    Else
        MsgBox("The file image1.jpg does not exist at C:\")
    End If
End Sub

Applies to