PowerShell PSHTML now support charts – Work in progress!

PSHTML now supports charts! So, why to wait? Let us explore it using PowerShell Polaris module. Yes, now my web server is powered up a bit. I can make presentation better, all using PowerShell.

Note: Ensure to checkout the Feature_Charts branch after cloning the PSHTML repo.

A lift and shift from GitHub shown below!

Import-Module Polaris -Verbose
Import-Module C:\Projects\PSHTML\PSHTML\PSHTML.psd1 -Verbose
New-PolarisGetRoute -Path "/barchart" -ScriptBlock {
    $BarCanvasID = "barcanvas"
    $HTMLPage = html { 
        head {
            title 'Bar Chart'
        body {
            h1 "PSHTML Graph"
            div {
                p {
                    "This is a bar graph"
                canvas -Height 400px -Width 400px -Id $BarCanvasID {
            script -src "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js" -type "text/javascript"
            script -content {
                $Data3 = @(4,1,6,12,17,25,18,17,22,30,35,44)
                $Labels = @("January","February","Mars","April","Mai","June","July","August","September","October","November","december")
                $dsb3 = New-PSHTMLChartBarDataSet -Data $data3 -label "2018" -BackgroundColor ([Color]::blue )
                New-PSHTMLChart -type bar -DataSet $dsb3 -title "Bar Chart Example" -Labels $Labels -CanvasID $BarCanvasID


Start-Polaris -Port 8080

Now, let me show a simple trick to plot chart for the count of files and folders in the given folder. For a demo I hard coded the path. Nothing great I did – Simply, replaced the value for $data3 and $labels variables as illustrated below!

$Data3 = @([System.IO.Directory]::GetDirectories("C:\Temp").Length , [System.IO.Directory]::GetFiles("C:\Temp").Length)
$Labels = @('Folders' , 'Files')

Enjoy PowerShell!

Leave a Reply
