Generate a chart with a varying number of series using LINQ Reporting Engine

Hi, I am currently evaluating whether the Reporting Engine fits our needs to generate Word reports dynamically based on data coming from our application. I was able to generate most of the elements to represent, but I am a bit stuck on a chart with several timeseries. The number of timeseries varies based on the perimeter chosen, and the values are not always synchronized.

Something like:
Report 1 : image.png (8.3 KB)
Report 2: image.png (3.4 KB)

Ideally, this would be done from a data in the format:

 	"Q":[
	{
		"Name": "Q1",
		"Values": [ 
			{"value":2,"time":"2022-04-23T18:00:00.000Z"}, 
			{"value":4,"time":"2022-04-23T18:15:00.000Z"}, 
			{"value":5,"time":"2022-04-23T18:45:00.000Z"}
		]
	},
	{
		"Name": "Q2",
		"Values": [ 
			{"value":3,"time":"2022-04-23T18:00:00.000Z"}, 
			{"value":3,"time":"2022-04-23T18:15:00.000Z"},
			{"value":2,"time":"2022-04-23T18:30:00.000Z"},
			{"value":2,"time":"2022-04-23T18:45:00.000Z"}
		]
	}
]

I tried by first combining the data myself in the format:

"Q":[ 
	{"Q1value":"2","Q2value":"3","time":"2022-04-23T18:00:00.000Z"}, 
	{"Q1value":"4","Q2value":"3","time":"2022-04-23T18:15:00.000Z"},
	{"Q2value":"2","time":"2022-04-23T18:30:00.000Z"},
	{"Q1value":"5","Q2value":"2","time":"2022-04-23T18:45:00.000Z"}
]

I did manage to get some results with this second format and the option “AllowMissingMembers”, but two issues remain:

  • The legend name stays visible even if there is no data
  • Is it possible to do something based on the first data model? That would be much more powerful for my use case

Thanks !

@Leyan

Did you consider Including Chart Series Dynamically? With this approach, you can define a chart template for a maximum possible number of items in Q as per the first form of your data. Then, you can remove extra series depending on an actual number of items in Q using removeif tags like this one:

<<removeif [Q.Count() < 5]>>

@Leyan

In this case, you may try using all unique time entries as categories using a foreach tag like this:

<<foreach [t in Q.SelectMany(q => q.Values).Select(v => v.time).Distinct().OrderBy(i => i)]>>

Then, x and y tags can be defined based on that as follows:

<<x [t]>>
<<y [Q.FirstOrDefault(q => q.Name == "Q1")?.Values?.FirstOrDefault(v => v.time == t)?.value]>>

Thank you for your answer, I made some progress. <<removeif […]>> seems interesting. The LINQ queries may get a bit complex, I will see if I can merge my data beforehand.

Something strange I found while testing: when configuring a report like this:
image.png (5.2 KB)

with source data like this:

"Q":[
	{
		"Name": "Q1",
		"FlowValues": [ 
			{"value":1,"time":"2022-04-23T18:00:00.000Z"}, 
			{"value":0,"time":"2022-04-23T18:15:00.000Z"}, 
			{"value":2,"time":"2022-04-23T18:29:00.000Z"}, 
			{"value":20,"time":"2022-04-23T18:45:00.000Z"},
			{"value":3,"time":"2022-04-23T19:15:00.000Z"}
		]
	},
	{
		"Name": "Q2",
		"FlowValues": [ 
			{"value":3,"time":"2022-04-23T18:00:00.000Z"}, 
			{"value":3,"time":"2022-04-23T18:15:00.000Z"},
			{"value":2,"time":"2022-04-23T18:37:00.000Z"},
			{"value":2,"time":"2022-04-23T18:45:00.000Z"}
		]
	}
]

I get a strange render in PDF format: one additional point has been added on the missing timestamp for Q1, but I don’t understand where the value comes from: it is not an existing value, it is not exactly linear interpolation, but it looks like it …

image.png (38.1 KB)

However, the same report in Docx format is fine:
image.png (22.7 KB)

Do you think it is a bug on Aspose side?

@Leyan

Yes, this might be a defect in Aspose.Words chart rendering mechanism. Could you please attach your output DOCX and PDF documents here for testing? We will check the documents and provide you more information.

BugPDF.7z (101.3 KB)
Here it is. It seems to be because I used the somewhat obscure setting “Connect data points with line” (when there is an empty value). In a PDF output, it seems to create an additional data point where the empty value is supposed to be.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-24871

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

The issues you have found earlier (filed as WORDSNET-24871) have been fixed in this Aspose.Words for .NET 23.3 update also available on NuGet.