Create a chart using dynamic data

Hi Aspose Team,

I’m trying to create a new chart (bar or pie), and I haven’t been able to replicate one example dynamically using data coming 100% from code. Ex:

X = Products (foreach -> Product.Name)
Y = Product Items (Product.Items.Count())

Do you have any examples or something I can use?

Thanks!

@OscarRojas If it is required to create chart from scratch programmatically, you can use Documentbuilder.InsertChart method. Please see our documentation for more information:
https://docs.aspose.com/words/net/working-with-charts/#insert-column-chart

Also, you can create the required chart in the template and fill it with data using LINQ Reporting Engine. For example see the following code and template:
Data object:

public class Product
{
    public string Name { get; set; }
    public int ItemsCount { get; set; }
}

Template:
in.docx (25.6 KB)
Code to fill template with data:

List<Product> products = new List<Product>
{
    new Product() { Name = "Apple", ItemsCount = 10 },
    new Product() { Name = "Pear", ItemsCount = 20 },
    new Product() { Name = "Banana", ItemsCount = 30 }
};

Document doc = new Document(@"C:\Temp\in.docx");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, products, "products");
doc.Save(@"C:\Temp\out.docx");

Output:
out.docx (22.9 KB)