Difficulty with multi line graphs with New-UDChart

I’m running version 2.6.2 and attempting to generate a multi line graph using a PSCustomObject. Have a CSV somewhat working but has issues when new data points are discover on later dates.

The input object: $devices

Device                Date           Type          Value
------                    ----              ----             -----
TTENG-0303     05/18/2020 SUB_PCT 143
TTENG-0293     05/18/2020 SUB_PCT 134
TTENG-0710     05/18/2020 SUB_PCT 145

Here is the code:

  $Charts1 = New-UDDashboard -Title "Charts multiple data points" -Content {
    New-UdChart -Title "Subscription Alerts" -Type Line -Endpoint {
      $colorIdx = -1;
      $devices = Get-AlertFiles;
      $devices | Out-UDChartData -LabelProperty 'Date' -Dataset @(
        $colorIdx++;
        $colors = '#2E2EFE', '#642EFE', '#FE2EF7', '#FF0040', '#FE642E', '#F7FE2E', '#2EFE2E', '#2EFEC8', '#9A2EFE', '#FE2E9A', '#8A4B08', '#868A08', '#5FB404', '#088A85', '#086A87', '#084B8A', '#5F04B4';
         ForEach-Object -InputObject $devices {
          [string]$value = $_.Value; [string]$label = $_.Device
          New-UDLineChartDataset -DataProperty $value -Label $label -BorderColor $colors[$colorIdx] -BorderWidth 2 -Fill $false;
        }
      )
    }
  }
  Start-UDDashboard -Dashboard $Charts1 -Port 10009 -AutoReload

Graph that I’m hoping to generate from a PSCustomObject but having difficulties. This graph was generated from the almost working CSV version.

Maybe I’ve been working too hard on this and my brain has turned to mush.

Thanks for any insights.

I was able to overcome the issue that was giving me difficulty and here is the solution. I’m not sure it is the most elegant solution but it works.

I was attempting to generate a line graph for a set of storage arrays that have over subscription alerts across multiple days. The difficulty that I faced was on the Nth day new alerts appeared that we not present on prior days. This caused the line graph to incorrectly associate a data point with the wrong graph line.

The resolution was to assign a common device id to each data point across the time span for which the graph was being generated.

05/19/2020,315,236,332,253,938,554,331,269,143,134,145,334
05/20/2020,315,236,332,253,938,554,331,269,143,134,145,334,1010,452

The last line above is showing 2 new data points on the 20th. Adding a common device ID to data points allow the new items to be moved to the end of the list rather that appear in the middle of the list somewhere.

Here is the New-UDChart logic.

  $Charts1 = New-UDDashboard -Title "Charts multiple data points" -Content {
    New-UdChart -Title "Subscription Alerts" -Type Line -Endpoint {

      $devices = Get-AlertFiles;
      Start-Sleep -seconds 1;
      # Select the longest Header/Label in the date range for the Chart
        $dayHeaders = Get-Content -Path $HeaderOut -Encoding ascii
        $dayCnt = $dayHeaders.Count - 1;
        $dayIdx = 0;
        $daysize1 = 0;
        for ($i = 0; $i -le $dayCnt; $i++) {
          $daysize = $dayHeaders[$i].Length;
          if ($daysize -gt $daysize1) {$dayIdx = $i; $daysize1 = $daysize}
        }
        $dh = @();
        $dh = $dayHeaders[$dayIdx].Split(" ")
      #

      $devices | Out-UDChartData -LabelProperty "Date" -Dataset @(
        $idxCnt = $dh.Count - 2;
        $colors = '#2E2EFE', '#642EFE', '#FE2EF7', '#FF0040', '#FE642E', '#F7FE2E', '#2EFE2E', '#2EFEC8', '#9A2EFE', '#FE2E9A', '#8A4B08', '#868A08', '#5FB404', '#088A85', '#086A87', '#084B8A', '#5F04B4';
        For ($idx=1; $idx -le $idxCnt; $idx++) {
          New-UDLineChartDataset -DataProperty $dh[$idx] -Label $dh[$idx] -BorderColor $colors[$idx - 1] -BorderWidth 2 -Fill $false;
        }
      )
    }
  }

  Start-UDDashboard -Dashboard $Charts1 -Port 10009 -AutoReload

But the real work happens in the function ‘Get-AlertFiles’ which sets up the object consumed by Out-UDChart Data. There are too many lines of code to paste here, but image here shows the logic flow.

Here is the graph generated. Not to exciting, but if there were any sharply increase lines it would an O’SHIT moment.

I don’t mind sharing any of this code. So just DM me if interested.