Microsoft Office Tutorials and References
In Depth Information
The ChartSheet host item
Open Visual Studio 2008 and create a new solution, as usual. Right-click on the
ExcelWorkbook.xlsx file of your Excel 2007 solution in the Solution Explorer , and
select Add New Excel Chart .
In the Chart.cs file, you can program your functionality. In this example, let's write
a code for the MouseUp event in the ChartSheet host item:
// MouseUp event registration in the Chart Host item.
private void InternalStartup()
{
this.MouseUp += new Microsoft.Office.Interop.Excel.
ChartEvents_MouseUpEventHandler(Chart4_MouseUp);
}
private void Chart4_MouseUp(int Button, int Shift, int x, int y)
{
// Set the constant value for range of cells
Globals.Sheet1.Range["B2", "B4"].Value2 = 15;
Globals.Sheet1.Range["C2", "C4"].Value2 = 18;
// Adding the sheet1 cells as data source
this.SetSourceData(Globals.Sheet1.Range["B2", "C4"],
Excel.XlRowCol.xlColumns);
// Chart display type
this.ChartType = Excel.XlChartType.xlConeColStacked100;
// Message to display the mouse moved
MessageBox.Show("Your clicked at X-axis: " + x.ToString() + "
and Y-axis: " + y.ToString());
}
The following screenshot shows the results of adding and executing the
preceding code:
 
Search JabSto ::




Custom Search