on Click over Slice in Pie Chart, Filter all records of that Slice of Pie Chart in Pivot Table

22 Views Asked by At

I want create a Pie Chart using Pivot Table data And OnClick over slice of Pie Chart, Filter all records in that Slice of Pie Chart in Pivot Table.My problem is I want Chart event Handling to work within the excel file without using browser based window. Basically I want to create Pivot Table within the Chart( just like chart within chart). I tried using Google.visualization google.visualization.events.addListener(source_visualization,event_name, handling_function) but it is browser based and i tried Chartjs even those are browser based. To my Findings, I think using Microsoft.Office.Interop.Excel is the Solution to my problem.

I was using Microsoft.Office.Interop.Excel nuget package as addon package to EPPlus Excel nuget package as ordinary excel nuget packages doesn't support Chart Event Handling only After using Microsoft.Office.Interop.Excel Chart Events Works. First, to test if Chart Event Function is triggered I wrote a simple program that is onClick over chart, ConsoleWrite("Chart Click"). But the Function doesn't get called and program exitted.

using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;

using Excel = Microsoft.Office.Interop.Excel;
using OfficeOpenXml;

class Program
{
    static void Main(string[] args)
    {
        try
        {
            Excel.Application excelApp = new Excel.Application();
            Excel.Workbook workbook = excelApp.Workbooks.Open("C:\\Users\\lenovo\\Downloads\\ColumnGemBox.xlsx");
            Excel.Worksheet worksheet = workbook.Sheets["Chart"] as Excel.Worksheet;
            Excel.ChartObjects chartObjects = worksheet.ChartObjects() as Excel.ChartObjects;
            Excel.ChartObject chartObject = (ChartObject)chartObjects.Item(1);

            // Handle chart events
            chartObject.Chart.MouseUp += new Excel.ChartEvents_MouseUpEventHandler(Chart_MouseUp);


            // Display Excel and wait for events
            excelApp.Visible = true;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception occurred: " + ex.Message);
        }
    }

    // Event handler for mouse click on the chart
    static void Chart_MouseUp(int button, int shift, int x, int y)
    {
        // Handle chart mouse click event here
        Console.WriteLine("Chart clicked!");
    }
}

Does Anyone know what is exact program here?

0

There are 0 best solutions below