Manually adding values to charts in excel c#

316 Views Asked by At

I'm working with Spire.XLS licenced pack and I need to find a way to set the values for a chart manually from a c# win form application, speaking about category labels to actual values to display inside, instead of being forced to use sheet.Range[], or at least be able to use single cell values separated one from another from a sheet and use those like an "extended range" for the values any idea if this is possible?

1

There are 1 best solutions below

0
Dheeraj Malik On BEST ANSWER

Yes, it is possible. See the following example which shows how to create a chart without using worksheet data range.

using Spire.Xls;

namespace Create_chart
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a workbook
            Workbook wb = new Workbook();
            
            //Get the first worksheet
            Worksheet sheet = wb.Worksheets[0];

            //Add a chart to the worksheet
            Chart chart = sheet.Charts.Add();

            //Add a series to the chart
            var series = chart.Series.Add();

            //Add data 
            series.EnteredDirectlyValues = new object[] { 10, 20, 30 };

            //Save the file
            wb.SaveToFile("result.xlsx", ExcelVersion.Version2013);
        }
    }
}

For more information, you can check this documentation: Create Chart without Using Worksheet Data Range in C#