Stephanevg / PSHTML

Cross platform Powershell module to generate HTML markup language
https://pshtml.readthedocs.io/en/latest/
Other
167 stars 43 forks source link

Out-PSHTMLDocument throws error when chart is added #223

Closed Stephanevg closed 5 years ago

Stephanevg commented 5 years ago

The following errors occurs

Exception calling "WriteLine" with "2" argument(s): "Input string was not in a correct format."
At C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PSHTML\PSHTML\PSHTML.psm1:6577 char:13
+             $writer.WriteLine($Line, "utf8")
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FormatException

This is the HTML document:

<html lang="en"  ><head ><meta charset="UTF-8"  /><meta name="author" content="Stephane van Gulick"  /><title >Pester REport</title><Script src='C:/Users/taavast3/OneDrive/Repo/Projects/OpenSource/PSHTML/PSHTML/Assets/Jquery/jquery-3.3.1.slim.min.js'></Script><Link rel='stylesheet' type=text/css href='C:/Users/taavast3/OneDrive/Repo/Projects/OpenSource/PSHTML/PSHTML/Assets/BootStrap/bootstrap.min.css' ><Script src='C:/Users/taavast3/OneDrive/Repo/Projects/OpenSource/PSHTML/PSHTML/Assets/BootStrap/bootstrap.min.js'></Script><Script src='C:/Users/taavast3/OneDrive/Repo/Projects/OpenSource/PSHTML/PSHTML/Assets/Chartjs/Chart.bundle.min.js'></Script></head><Body ><div Class="container"  ><div Class="Summary"  ><h1 >Pester Reults - C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PsNunit\output.json</h1><Table ><thead ><tr ><td >TotalCount</td><td >PassedCount</td><td >FailedCount</td><td >SkippedCount</td><td >PendingCount</td><td >InconclusiveCount</td></tr></thead><tbody ><tr ><td >5</td><td >2</td><td >3</td><td >0</td><td >0</td><td >0</td></tr></tbody></Table><canvas Width="400px" Id="Chart_Summary" Height="400px"  ></canvas></div><div Class="Time"  ><p >Pester Run took 0 days 0 hours  minutes 2 seconds to execute</p></div><div Class="FailedTests"  ><h2 >Failed tests</h2><p >Total failed tests: 3</p><h3 ><Table ><thead ><tr ><td >Name</td><td >Describe</td><td >Parameters</td><td >FailureMessage</td><td >Time</td><td >StackTrace</td></tr></thead><tbody ><tr ><td >My It block 2</td><td >My DEscribe block</td><td ></td><td >Expected $false, but got $true.</td><td ></td><td >at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PsNunit\_TestMaterial\Woop.Tests.ps1: line 16
16:                         $true | should be $false</td></tr></tbody></Table></h3><h3 ><Table ><thead ><tr ><td >Name</td><td >Describe</td><td >Parameters</td><td >FailureMessage</td><td >Time</td><td >StackTrace</td></tr></thead><tbody ><tr ><td >My It block 5</td><td >My DEscribe block</td><td ></td><td >Expected $false, but got $true.</td><td ></td><td >at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PsNunit\_TestMaterial\Woop.Tests.ps1: line 19
19:                         $true | should be $false</td></tr></tbody></Table></h3><h3 ><Table ><thead ><tr ><td >Name</td><td >Describe</td><td >Parameters</td><td >FailureMessage</td><td >Time</td><td >StackTrace</td></tr></thead><tbody ><tr ><td >My It block 6</td><td >My DEscribe block</td><td ></td><td >Expected $false, but got $true.</td><td ></td><td >at <ScriptBlock>, C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PsNunit\_TestMaterial\Woop.Tests.ps1: line 22
22:                         $true | should be $false</td></tr></tbody></Table></h3></div><div Class="PassedTests"  ><h2 >Passed tests</h2><p >Total Passed tests: 2</p><h3 ><Table ><thead ><tr ><td >Name</td><td >Describe</td><td >Parameters</td><td >FailureMessage</td><td >Time</td><td >StackTrace</td></tr></thead><tbody ><tr ><td >My It block 3</td><td >My DEscribe block</td><td ></td><td ></td><td ></td><td ></td></tr></tbody></Table></h3><h3 ><Table ><thead ><tr ><td >Name</td><td >Describe</td><td >Parameters</td><td >FailureMessage</td><td >Time</td><td >StackTrace</td></tr></thead><tbody ><tr ><td >My It block 1</td><td >My DEscribe block</td><td ></td><td ></td><td ></td><td ></td></tr></tbody></Table></h3></div><script >var ctx = document.getElementById("Chart_Summary").getContext('2d'); var myChart = new Chart(ctx, {"type":"pie","data":{"labels":["Passed","Failed","Skipped","Inconclusive"],"datasets":[{"borderColor":"white","borderWidth":1,"backgroundColor":null,"hoverBackgroundColor":[null],"HoverBorderColor":null,"HoverBorderWidth":0,"data":[2,3,0,0],"label":"Pester Data"}]},"options":{"barPercentage":1,"categoryPercentage":1,"responsive":false,"barThickness":null,"maxBarThickness":0,"offsetGridLines":true,"scales":{"yAxes":[{"ticks":{"beginAtZero":true}}],"xAxes":[""]},"title":{"display":true,"text":"Pester run summary"}}} );</script></div><footer ></footer></Body></html>
Stephanevg commented 5 years ago

I think I fixed this one.

the following example doesn't throw an error: (Example taken from the examples folder of the module it self).

<# $Searcher = New-Object -ComObject Microsoft.Update.Searcher;                                      
        $Searcher.GetTotalHistoryCount()                                            
        $AllUpdatesInstalled = $Searcher.GetTotalHistoryCount()                     
        $Updates = $Searcher.QueryHistory(0,$AllUpdatesInstalled)
        #>
import-module C:\Users\taavast3\OneDrive\Repo\Projects\OpenSource\PSHTML\PSHTML\PSHTML.psd1 -force

$BarCanvasID = "barcanvas"
$HTMLPage = html { 
    head {
        title 'Chart JS Demonstration'

    }
    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 (Get-pshtmlColor -Color  blue)

            New-PSHTMLChart -type bar -DataSet $dsb3 -title "Bar Chart Example" -Labels $Labels -CanvasID $BarCanvasID

        }

    }
}

$OutPath = "$Home\BarChart1.html"
Out-PSHTMLDocument -OutPath $outpath -HTMLDocument $HtmlPage
#$HTMLPage | out-file -FilePath $OutPath -Encoding utf8
start $outpath