none
Convert Pie Graph object created on .Net libraries in PowerShell to Html.

    Pertanyaan

  • I am creating a Pie Chart using .Net Libraries. I am able to show that chart over Windows Form. Just want to know if there is any way I can pull the chart object in html and add to my web page.

    I am able to save the pie chart in a Jpeg image, but that give me limited option to display it on a web page.

    $service = get-service *
    $array = @()
    
    $type = "STOPPED","RUNNING"
    foreach ( $t in $type ) 
                         { $ser = $service | where { $_.Status -eq $t }
                           $count = $ser.name.count 
                           $system = New-Object -TypeName PSObject -Property $info
                           $info = @{
                                     "name" = $t
                                     "value" = $count
                                     }
                           $array += $system
                         }
    
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Windows.Forms.DataVisualization
    $Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
    $ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea
    $Series = New-Object -TypeName System.Windows.Forms.DataVisualization.Charting.Series
    $ChartTypes = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]
    $Series.ChartType = $ChartTypes::Pie
    $Chart.Series.Add($Series)
    $Chart.ChartAreas.Add($ChartArea)
    $ChartArea.Area3DStyle.Enable3D=$True
    $ChartArea.Area3DStyle.Inclination = 50
    
    $Chart.Series['Series1'].Points.DataBindXY($array.name, $array.value)
    
    
    $Chart.Width = 700
    $Chart.Height = 400
    $Chart.Left = 10
    $Chart.Top = 10
    $Chart.BackColor = [System.Drawing.Color]::White
    $Chart.BorderColor = 'Black'
    $Chart.BorderDashStyle = 'Solid'
    
    $ChartTitle = New-Object System.Windows.Forms.DataVisualization.Charting.Title
    $ChartTitle.Text = 'Service Status'
    $Font = New-Object System.Drawing.Font @('Microsoft Sans Serif','12', [System.Drawing.FontStyle]::Bold)
    $ChartTitle.Font =$Font
    $Chart.Titles.Add($ChartTitle)
    
    $Chart.Series['Series1']['PieLineColor'] = 'Black'
    $Chart.Series['Series1']['PieLabelStyle'] = 'Outside'
    $Chart.Series['Series1'].Label = "#VALX (#VALY)"
    
    #region Windows Form to Display Chart
    $AnchorAll = [System.Windows.Forms.AnchorStyles]::Bottom -bor [System.Windows.Forms.AnchorStyles]::Right -bor
        [System.Windows.Forms.AnchorStyles]::Top -bor [System.Windows.Forms.AnchorStyles]::Left
    $Form = New-Object Windows.Forms.Form
    $Form.Width = 740
    $Form.Height = 490
    $Form.controls.add($Chart)
    $Chart.Anchor = $AnchorAll
     
    
    
    $Form.Add_Shown({$Form.Activate()})
    [void]$Form.ShowDialog()
    #endregion Windows Form to Display Chart
    
    $Chart.SaveImage('F:\Web_pages\test\pie.jpeg', 'jpeg')

    • Dipindahkan oleh Bill_Stewart Selasa, 31 Juli 2018 15.03 Off-topic
    Senin, 25 Juni 2018 03.23

Semua Balasan

  • You will have to rewrite it in C#.  Desktop APIs do not work in IIS.

    Your question is not a scripting question.  It is about IIS development.  You need to post this in the ASP.net forum. https://forums.asp.net/


    \_(ツ)_/

    Senin, 25 Juni 2018 03.30
  • it is just a question of converting PowerShell Object in HTML. Like we convert file data and other stuff.
    Sabtu, 04 Agustus 2018 17.08
  • it is just a question of converting PowerShell Object in HTML. Like we convert file data and other stuff.

    There is no method in PowerShell to do this.  You can create charts in Excel that can be exported as HTML.  This cannot be doe with the old WinForms Chart object.


    \_(ツ)_/

    Sabtu, 04 Agustus 2018 18.02