Create a line chart with chart.js and powershell

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
alwo23@hotmail.com
Posts: 28
Joined: Sat Sep 28, 2013 1:56 am

Create a line chart with chart.js and powershell

Post by alwo23@hotmail.com » Wed Jul 03, 2019 12:06 am

Hey everybody,
i need help to create a line Chart with PowerShell. I have a pscostumobject:

foreach ($item in $objectcollection['getEmailAppUsageUserCounts'])
{
$objR6 = [PSCustomObject]@{
'Name' = 'Mail for Mac';
'Count' = $item.'Mail for Mac';
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'Outlook for Mac'
'Count' = $item.'Outlook for Mac'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'Outlook for Windows'
'Count' = $item.'Outlook for Windows'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'Outlook for Mobile'
'Count' = $item.'Outlook for Mobile'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'Other for Mobile'
'Count' = $item.'Other for Mobile'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'Outlook for Web'
'Count' = $item.'Outlook for Web'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'POP3 App'
'Count' = $item.'POP3 App'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'IMAP4 App'
'Count' = $item.'IMAP4 App'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
$objR6 = [PSCustomObject]@{
'Name' = 'SMTP App'
'Count' = $item.'SMTP App'
'Date' = $item.'Report Date'
}
$EmailAppUsageUserCountstable.add($objR6)
}
The $objectcollection i created with the following Code:
$objectcollection = @{}
foreach ($report in $O365Reports)
{
$UsageData = Get-UsageReportData -ClientID $ClientID -ClientSecret $ClientSecret -TenantName $TenantName
if ($UsageData)
{
$UsageData | add-member -membertype NoteProperty -name 'Office365Report' -Value $Report
$objectCollection.Add($($Report), $UsageData)
}
else
{
$objResults = New-Object -Type PSObject
$objResults | add-member -membertype NoteProperty -name 'Office365Report' -Value $Report
$objectCollection.Add($($Report), $objResults)
}
}
Now i will create a line Chart from the results. The result is:
Name Count Date
---- ----- ----
Mail for Mac 2019-06-02
Outlook for Mac 2019-06-02
Outlook for Windows 6 2019-06-02
Outlook for Mobile 1 2019-06-02
Other for Mobile 11 2019-06-02
Outlook for Web 2019-06-02
POP3 App 2019-06-02
IMAP4 App 2019-06-02
SMTP App 2019-06-02
Mail for Mac 2019-06-03
Outlook for Mac 2019-06-03
Outlook for Windows 39 2019-06-03
Outlook for Mobile 1 2019-06-03
Other for Mobile 17 2019-06-03
Outlook for Web 2019-06-03
POP3 App 2019-06-03
IMAP4 App 2019-06-03
SMTP App 1 2019-06-03
Mail for Mac 2019-06-04
Outlook for Mac 2019-06-04
Outlook for Windows 40 2019-06-04
Outlook for Mobile 1 2019-06-04
Other for Mobile 17 2019-06-04
Outlook for Web 2019-06-04
POP3 App 2019-06-04
IMAP4 App 2019-06-04
SMTP App 1 2019-06-04
Mail for Mac 2019-06-05
Outlook for Mac 2019-06-05
Outlook for Windows 43 2019-06-05
Outlook for Mobile 1 2019-06-05
Other for Mobile 16 2019-06-05
Outlook for Web 1 2019-06-05

The Problem is now that i have multiple names with multiple Counts on different days. I would like to convertb now the result to following Schema:

Mail for Mac 2019-06-02 6
2019-06-03 10
and so on
The same for the other names.
In the line Chart i would like this:
Anmerkung 2019-07-03 090438.png
Anmerkung 2019-07-03 090438.png (46.8 KiB) Viewed 946 times
Manually is the chart working but not in the script.
Have anyone an idea?

Locked