Sample code and excel attached
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Aspose.Cells;
using Aspose.Cells.Charts;
using Aspose.Cells.Drawing;
using System.Drawing;
namespace AsposeSampleProject
{
class Program
{
static void Main(string[] args)
{
Workbook wb = new Workbook(@"C:\Working\2\testData.xlsx");
Worksheet wrktest = wb.Worksheets["__ifnet"];
//Adding a new worksheet to the Workbook object
int sheetIndex = wb.Worksheets.Add(SheetType.Chart);
//Obtaining the reference of the newly added worksheet by passing its sheet index
Worksheet worksheet = wb.Worksheets[sheetIndex];
int chartIndex = worksheet.Charts.Add(Aspose.Cells.Charts.ChartType.Line, 1, 1, 25, 30);
//Accessing the instance of the newly added chart
Aspose.Cells.Charts.Chart chart = worksheet.Charts[chartIndex];
Cells cell = wrktest.Cells;
//Adding NSeries (chart data source) to the chart ranging from "A1" cell to "B4"
chart.NSeries.Add("__ifnet!B2:E10", true);
chart.NSeries.CategoryData = "__ifnet!A2:A10";
chart.NSeries.SecondCatergoryData = "__ifnet!A2:A10";
int i;
for ( i = 0; i < 3; i++)
{
string index = ((char)(66 + i)).ToString() + "1";
chart.NSeries[i].Name = cell[index].Value.ToString();
chart.NSeries[i].Type = Aspose.Cells.Charts.ChartType.Line;
chart.NSeries[i].Line.Weight = WeightType.HairLine;
DataLabels datalabels = chart.NSeries[i].DataLabels;
datalabels.ShowValue = false;
}
string cellindex = ((char)(66 + i)).ToString() + "1";
chart.NSeries[i].Name = cell[cellindex].Value.ToString();
chart.NSeries[i].Type = Aspose.Cells.Charts.ChartType.Line;
chart.NSeries[i].PlotOnSecondAxis = true;
chart.NSeries[i].Line.IsVisible = true;
chart.SecondCategoryAxis.IsVisible = true;
Console.WriteLine("Applying Formatting ...");
//Formatting chart area
chart.PlotArea.Area.BackgroundColor = Color.White;
chart.ChartArea.Area.BackgroundColor = Color.White;
chart.PlotArea.Area.ForegroundColor = Color.White;
chart.ChartArea.Area.ForegroundColor = Color.White;
chart.Name = "Sample Sheet";
chart.Title.Text = "Sample Chart";
chart.SizeWithWindow = true;
chart.ValueAxis.IsAutomaticMajorUnit = true;
chart.SecondValueAxis.IsAutomaticMajorUnit = true;
chart.SecondValueAxis.IsVisible = true;
chart.ValueAxis.IsAutomaticMaxValue = true;
chart.SecondValueAxis.IsAutomaticMaxValue = true;
chart.Calculate();
wb.Save(@"C:\Working\2\testDataResult.xlsx");
}
}
}