Udostępnij za pośrednictwem


Chart.Calculate Event

Definition

Occurs after the Chart control plots new or changed data.

public:
 event Microsoft::Office::Interop::Excel::ChartEvents_CalculateEventHandler ^ Calculate;
event Microsoft.Office.Interop.Excel.ChartEvents_CalculateEventHandler Calculate;
member this.Calculate : Microsoft.Office.Interop.Excel.ChartEvents_CalculateEventHandler 
Event Calculate As ChartEvents_CalculateEventHandler 

Event Type

Examples

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

    chart1.Calculate +=
        new Excel.ChartEvents_CalculateEventHandler(
        chart1_Calculate);

    // 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")
    CalculateChart.SetSourceData(Me.Range("A1", "B5"), _
        Excel.XlRowCol.xlColumns)
    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