Chart.Calculate Event


Occurs after the Chart control plots new or changed data.

public event Microsoft.Office.Interop.Excel.ChartEvents_CalculateEventHandler Calculate;


The following code example creates a Chart with a handler for the Calculate event that displays a message box when the source data of the chart changes.

private void DisplayWhenCalculated()
    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.SetSourceData(this.Range["A1", "B5"], 
    chart1.ChartType = Excel.XlChartType.xl3DColumn;

    chart1.Calculate +=
        new Excel.ChartEvents_CalculateEventHandler(

    // This will raise the Calculate event.
    this.Range["A1"].Value2 = 11;

void chart1_Calculate()
    MessageBox.Show("The chart plotted new data.");
WithEvents CalculateChart As Microsoft.Office.Tools.Excel.Chart

Private Sub DisplayWhenCalculated()
    Me.Range("A1", "A5").Value2 = 22
    Me.Range("B1", "B5").Value2 = 55

    CalculateChart = Me.Controls.AddChart(Me.Range("D2", "H12"), _
    CalculateChart.SetSourceData(Me.Range("A1", "B5"), _
    CalculateChart.ChartType = Excel.XlChartType.xl3DColumn

    ' This will raise the Calculate event.
    Me.Range("A1").Value2 = 11
End Sub

Sub CalculateChart_Calculate() Handles CalculateChart.Calculate
    MsgBox("The chart plotted new data.")
End Sub

Applies to