I'm trying to create a simple line chart that has a data set similar to the following :
[year:2018,month:1,count:1];[year:2018,month:2,count: 54][year:2018,month:3,count:123] [year:2019,month:1,count:347]; [year:2019,month:4,count:503]; [year:2019,month:5,count:52]Basically showing my for each year how many widgets were ordered for each month. Some months return null when we've not sold any widgets.However no matter what I do I'm getting stuck at my series and either everything s displayed on one month, or nothing at all.I'm sure it's a missing for each loop in the series but no luck so far.
Discussion posts and replies are publicly visible
Hi Paul
If this is what you're looking for:
...then this is how I made it, based upon your data:
load( local!monthNumbers: fn!enumerate(12)+1, local!monthNames: { "January", "February", "March:", "April", "May", "June", "July", "August", "September", "October", "November", "December" }, local!data: { {year:2018,month:1,count:1}, {year:2018,month:2,count: 54}, {year:2018,month:3,count:123}, {year:2019,month:1,count:347}, {year:2019,month:4,count:503}, {year:2019,month:5,count:52} }, { a!lineChartField( categories: a!forEach( items: local!data, expression: fn!concat( fn!displayvalue(fv!item.month,local!monthNumbers, local!monthNames,""), " ", fv!item.year ) ), series: a!chartSeries( label: "Month/Year", data: a!forEach( items: local!data, expression: fv!item.count ) ) ) } )
I might suggest that a line chart may not be the best way to represent this data as "number of widgets ordered per month" sounds quite discrete, and a line chart kind of communicates a more continuous set of changing data. But it;'s only my personal view.
load( local!data: { { year: 2018, month: 1, count: 1 }, { year: 2018, month: 2, count: 54 }, { year: 2018, month: 3, count: 123 }, { year: 2019, month: 1, count: 347 }, { year: 2019, month: 4, count: 503 }, { year: 2019, month: 5, count: 52 } }, local!months: { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }, local!years: union( local!data.year, local!data.year ), local!yearsData: a!forEach( items: local!years, expression: local!data[wherecontains( fv!item, tointeger( local!data.year ) )] ), a!lineChartField( label: "Example:", categories: local!months, series: { a!forEach( items: local!yearsData, expression: a!chartSeries( label: local!years[fv!index], data: with( locaL!currentValue: fv!item, a!forEach( items: local!months, expression: if( isnull( cast( typeof( 1 ), locaL!currentValue[wherecontains( fv!index, tointeger( local!currentValue.month ) )].count ) ), 0, cast( typeof( 1 ), locaL!currentValue[wherecontains( fv!index, tointeger( local!currentValue.month ) )].count ) ) ) ) ) ) }, xAxisTitle: "Month", yAxisTitle: "year", showLegend: true ) )
Nice!