Create array in ASPOSE at output level

Hi,
I try to create some dynamic report with aspose and I can manage only the template for the output result. I can’t develop at the .NET level.

Here the code of my template in word :

So, I have to display a chart showing a cumulative value for each time step and for each entity, like this :

I have only the fonction Query.GetDataSamples() that return a TimeSeries (Time and instant value).
So, I do a nested foreach in order to compute the cumulative value for each Entity (pluvio) and it works.
But, how can I reorganise this datas in a structure in order to pass this structure to a chart like in the picture ?
Can I create an array of three attributes like TIME, ENTITY and VALUE ?
I get some errors when I try this, and I’m not even sure that’s the right way to go about it.
Can you help me please ?
Thank you in advance and sorry for my English.

@deid I will consult with our LINQ Reporting Engine developers and get back to you soon.

Thank you Alexey

@deid

The following code shows how to transform similar data as per the requirement:

List<DataItem> items = new List<DataItem>
{
    new DataItem { Date = "12/1/24", Value = 1 },
    new DataItem { Date = "12/2/24", Value = 2 },
    new DataItem { Date = "12/3/24", Value = 3 }
};

DocumentBuilder builder = new DocumentBuilder();

builder.Writeln(@"
    <<var [str = items
        .Select(i => new
            { 
                i.Date,
                i.Value,
                Sum = i.Value + items.TakeWhile(i2 => i2 != i).Sum(i2 => i2.Value)
            })]>>");
            
builder.Writeln("<<foreach [in str]>><<[Date]>> - <<[Value]>> - <<[Sum]>>; <</foreach>>");

ReportingEngine engine = new ReportingEngine();
engine.BuildReport(builder.Document, items, "items");

Console.WriteLine(builder.Document.GetText().Trim()); // Prints "12/1/24 - 1 - 1; 12/2/24 - 2 - 3; 12/3/24 - 3 - 6;"

//----------------------------------------------------------

public class DataItem
{
    public string Date { get; set; }
    public double Value { get; set; }
}

In a template, str can be used further to build a chart.

Thank you Ivan for your reply.
I’ll test your code immediately.

1 Like

Ivan,
I can’t test totally your code, because I haven’t à developer PC. I can’t install VS Code or similar in order to test all your code, so I tested the parts that can go in the template.
I think there is a problem because the first value of “Sum” is not 0 or the first value of the list, but already the cumulative sum of all items.
I think is not optimized, because I get an increment of “Sum” but the initial value start with the global sum of values.
I think that the problem is here : “TakeWhile(i2 => i2 != i)”. The behaviour of TakeWhile seem :

  • take all except “i”
    instead of
  • take all until “i”
    Any idea ?
    Thanks

@deid

Here is a quote from the official reference of TakeWhile:

Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.

So, it behaves as expected. Furthermore, code provided in my previous comment can be run to ensure this. Upon running, it prints “12/1/24 - 1 - 1; 12/2/24 - 2 - 3; 12/3/24 - 3 - 6;” for the pattern “date - value - cumulative sum”, which fulfills the original requirement.

I am afraid, without knowing what Query.GetDataSamples() returns, how it is implemented, and how the described approach is applied within a template, it is hard to say what is wrong. Please provide these details, so we could assist further.

@deid

Just a guess. If an item of Query.GetDataSamples() appears to be a structure rather than a class instance, then TakeWhile(i2 => i2 != i) should be changed to TakeWhile(i2 => !i2.Equals(i)). Without the requested details, it is hard to tell more.

@ivan.lyagin
Yes, you are right, GetDataSamples return me a class instance. So, I check your code but I have an error

I’m sorry, but I don’t have access to the underlying code.
Maybe this class must implement or inherit from another class, in order to compute the EQUALS function ?
Thanks

@deid

Yet another thing to try is TakeWhile(i2 => !object.Equals(i2, i)). If none of the provided options work, then I am afraid, we cannot suggest something else, since we cannot reproduce the issue on our end without requested details.

@ivan.lyagin
Unfortunately it doesn’t work.
But please, tell me how can I set an objects array like your code :

List<DataItem> items = new List<DataItem>
{
    new DataItem { Date = "12/1/24", Value = 1 },
    new DataItem { Date = "12/2/24", Value = 2 },
    new DataItem { Date = "12/3/24", Value = 3 }
};

but with the ASPOSE syntax at the template level.
I want to create a POC and I can’t create a structure like this.

I try something like this but it doesn’t work :
<<var [struct = new [] {name = " firstelement", maxvolume = 5}, {name = "secondelement", maxvolume = 8}, {name = "thirdelement", maxvolume = 2}]>>

I get this :

Thank you

@deid

There is no way to do this. I am afraid, LINQ Reporting Engine was never meant for writing complete C# programs using templates. The engine provides only a limited set of C# features.

Without more information, there is nothing else we can suggest. Even a full template rather than its part could shed a bit more light.