none
C# Using EPPlus to draw a chart in Excel RRS feed

  • Question

  • In C# I am using EPPLus to draw a graph in the Excel.

    I have data say

    P1_Value : 22,43,56,87
    P2_Value : 9,2,7,5
    My Requirement

    I need to plot the different coordinates {(22,9),(43,2),(56,7),(87,5)} on the graph.

    Currently my code plots P1_Value against  P2_Value taking P2_Value as Category instead of as numbers. So the X-Axis values do not have sequential values. but it appears as 9,2,7,5 on the X-Axis.

    My Current Code

      ExcelLineChart lineChart = workSheet.Drawings.AddChart("lineChart", eChartType.Line) as ExcelLineChart;
            lineChart.Title.Text = GraphTitle;
             var rangeLabel = workSheet.Cells["D2:D2571"];
             var range1 = workSheet.Cells["C2:C2571"];
    
            lineChart.Series.Add(range1, rangeLabel);
    
            lineChart.Series[0].Header = workSheet.Cells["A1"].Value.ToString();
             lineChart.Legend.Position = eLegendPosition.Right;
            lineChart.SetSize(600, 300);
    
            lineChart.SetPosition(5, 0, 1, 0);


    Any help\pointers are really appreciated. Thanks in advance.

    Tuesday, March 27, 2018 9:54 AM

All replies

  • You want to make a Scater chart, not a line chart.

    So use eChartType.XYScatterLines as parameter and ExcelScatterChart as cast and variable type.

    Tuesday, March 27, 2018 1:32 PM
  • @boothwine Thanks a lot.

    Changing to scatter graph did the work.

    Wednesday, March 28, 2018 4:35 PM
  • Hi jeyAntoni,

    Thank you for posting here.

    For your question is more related to third party API, please post your question in GitHub Issues.

    https://github.com/JanKallman/EPPlus/issues

    The CLR Forum discuss and ask questions about .NET Framework Base Classes (BCL) such as Collections, I/O, Regigistry, Globalization, Reflection. Also discuss all the other Microsoft libraries that are built on or extend the .NET Framework, including Managed Extensibility Framework (MEF), Charting Controls, CardSpace, Windows Identity Foundation (WIF), Point of Sale (POS), Transactions.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 29, 2018 7:49 AM