poshud/pages/charts.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
$BasicChart = {
    New-UDChart -Title "Cost of Bitcoin" -Type Line -Endpoint {

        $30DaysBack = [DateTime]::Now.AddDays(-30)
        0..30 | ForEach-Object {
            [PSCustomObject]@{ 
                Date = $30DaysBack.AddDays($_).ToShortDateString()
                Price = (Get-Random -Minimum 5000 -Maximum 20000)
            }
        } | Out-UDChartData -LabelProperty "Date" -DataProperty "Price" -DatasetLabel "Price to USD"
    }
}

$AutoRefreshChart = {
    New-UDChart -Title "People Living in Madison" -Type Line -Endpoint {

        $30DaysBack = [DateTime]::Now.AddYears(-30)
        0..30 | ForEach-Object {
            [PSCustomObject]@{ 
                Year = $30DaysBack.AddDays($_).Year
                Population = (Get-Random -Minimum 50000 -Maximum 250000)
            }
        } | Out-UDChartData -LabelProperty "Year" -DataProperty "Population" -DatasetLabel "Population"
    } -AutoRefresh -RefreshInterval 5
}

$CustomColors = {
    New-UDChart -Title "Packets per second" -Type Bar -Endpoint {
        30..0 | ForEach-Object {
            [PSCustomObject]@{ 
                Minute = " -$_"
                PacketsPerSecond = (Get-Random -Minimum 50000 -Maximum 250000)
            }
        } | Out-UDChartData -LabelProperty "Minute" -DataProperty "PacketsPerSecond" -DatasetLabel "Packets per second" -BackgroundColor "#FF0000" -BorderColor "#6F0000" -HoverBackgroundColor "#CC0786" -HoverBorderColor "#900786"
    } -BackgroundColor "#252525" -FontColor "#FFFFFF"
}



$MultiDatasetChart = {
    New-UDChart -Title "Feature by operating system" -Type Line -AutoRefresh -RefreshInterval 7 @Colors -Endpoint {
        $features = @();
        $features += [PSCustomObject]@{ "OperatingSystem" = "Windows 10"; "FormsDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "WPFDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "UniversalDashboard" = (Get-Random -Minimum 10 -Maximum 10000) }
        $features += [PSCustomObject]@{ "OperatingSystem" = "Windows 8"; "FormsDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "WPFDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "UniversalDashboard" = (Get-Random -Minimum 10 -Maximum 10000) }
        $features += [PSCustomObject]@{ "OperatingSystem" = "Windows 7"; "FormsDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "WPFDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "UniversalDashboard" = (Get-Random -Minimum 10 -Maximum 10000) }
        $features += [PSCustomObject]@{ "OperatingSystem" = "Ubuntu 16.04"; "FormsDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "WPFDesigner" = (Get-Random -Minimum 10 -Maximum 10000);  "UniversalDashboard" = (Get-Random -Minimum 10 -Maximum 10000) }
        $features| Out-UDChartData -LabelProperty "OperatingSystem" -Dataset @(
            New-UDChartDataset -DataProperty "FormsDesigner" -Label "Forms Designer" -BackgroundColor "#80962F23" -HoverBackgroundColor "#80962F23"
            New-UDChartDataset -DataProperty "WPFDesigner" -Label "WPF Designer" -BackgroundColor "#8014558C" -HoverBackgroundColor "#8014558C"
            New-UDChartDataset -DataProperty "UniversalDashboard" -Label "Universal Dashboard" -BackgroundColor "#803AE8CE" -HoverBackgroundColor "#803AE8CE"
        )
    }
}

New-UDPage -Name "Charts" -Icon area_chart -Content {
    New-UDPageHeader -Title "Charts" -Icon "area-chart" -Description "Visual data using dynamic charts based on ChartJS" -DocLink "https://adamdriscoll.gitbooks.io/powershell-universal-dashboard/content/charts.html"
    New-UDExample -Title "Basic Charts" -Description "Create basic charts from any type of data." -Script $BasicChart
    New-UDExample -Title "Auto Refreshing Charts" -Description "Automatically refresh chart data on an interval" -Script $AutoRefreshChart
    New-UDExample -Title "Custom colors" -Description "Adjust colors of different components within the chart." -Script $CustomColors
    New-UDExample -Title "Multiple Datasets" -Description "Combine data from more than one dimension on a single chart." -Script $MultiDatasetChart
}