New-ImageChart
Creates an image chart from definitions.
Syntax
New-ImageChart [-Annotation <Object[]>] [-AnnotationsDefinition <ScriptBlock>] [-Background <ChartColor>] [-ChartsDefinition] <ScriptBlock> [-Dpi <Double>] -FilePath <String> [-Height <Int32>] [-Options <ChartRenderOptions>] [-PassThru] [-SecondaryYTitle <String>] [-Show] [-ShowGrid] [-Subtitle <String>] [-Theme <ChartTheme>] [-Title <String>] [-Watermark <VisualWatermark[]>] [-Width <Int32>] [-XLabel <String[]>] [-XTitle <String>] [-YTitle <String>] [<CommonParameters>]#ScriptBlockNew-ImageChart [-Annotation <Object[]>] [-AnnotationsDefinition <ScriptBlock>] [-Background <ChartColor>] -ChartScript <ScriptBlock> [-Dpi <Double>] -FilePath <String> [-Height <Int32>] [-Options <ChartRenderOptions>] [-PassThru] [-SecondaryYTitle <String>] [-Show] [-ShowGrid] [-Subtitle <String>] [-Theme <ChartTheme>] [-Title <String>] [-Watermark <VisualWatermark[]>] [-Width <Int32>] [-XLabel <String[]>] [-XTitle <String>] [-YTitle <String>] [<CommonParameters>]#ChartScriptNew-ImageChart [-Annotation <Object[]>] [-AnnotationsDefinition <ScriptBlock>] [-Background <ChartColor>] -Chart <Chart> [-Dpi <Double>] -FilePath <String> [-Height <Int32>] [-Options <ChartRenderOptions>] [-PassThru] [-SecondaryYTitle <String>] [-Show] [-ShowGrid] [-Subtitle <String>] [-Theme <ChartTheme>] [-Title <String>] [-Watermark <VisualWatermark[]>] [-Width <Int32>] [-XLabel <String[]>] [-XTitle <String>] [-YTitle <String>] [<CommonParameters>]#ChartNew-ImageChart [-Annotation <Object[]>] [-AnnotationsDefinition <ScriptBlock>] [-Background <ChartColor>] -Definition <ChartDefinition[]> [-Dpi <Double>] -FilePath <String> [-Height <Int32>] [-Options <ChartRenderOptions>] [-PassThru] [-SecondaryYTitle <String>] [-Show] [-ShowGrid] [-Subtitle <String>] [-Theme <ChartTheme>] [-Title <String>] [-Watermark <VisualWatermark[]>] [-Width <Int32>] [-XLabel <String[]>] [-XTitle <String>] [-YTitle <String>] [<CommonParameters>]#DefinitionDescription
Use this cmdlet to render one or more chart definitions into a final image file.
Examples
Create a simple bar chart and save it
New-ImageChart -ChartsDefinition {
New-ImageChartBar -Name 'Q1' -Value 12,18,25 -Color CornflowerBlue
New-ImageChartBar -Name 'Q2' -Value 14,20,28 -Color Orange
} -FilePath chart.png -XTitle 'Month' -YTitle 'Revenue'Builds chart definitions inside a script block and renders them into a PNG file.
Create a line chart with annotations and preview it
$defs = @(
New-ImageChartLine -Name 'CPU' -Value 35,42,58,61,49 -Color LimeGreen -Smooth
)
$ann = @(
New-ImageChartAnnotation -X 3 -Y 61 -Text 'Peak' -Arrow
)
New-ImageChart -Definition $defs -Annotation $ann -FilePath cpu-usage.png -Theme Dark -ShowGrid -ShowRenders a themed line chart and overlays an annotation highlighting the peak value.
Title, category labels, and stacked bars from CSV data
$builds = Import-Csv builds.csv # Day, Passed, Failed
New-ImageChart -Title 'Builds by result' -Subtitle 'Week 41' -XLabel $builds.Day -FilePath builds.png -Options (New-ImageChartOptions -BarLayout Stacked -ShowLegend) {
New-ImageChartBar -Name Passed -Value $builds.Passed
New-ImageChartBar -Name Failed -Value $builds.Failed
}Titles, category labels, and the bar layout are parameters, so the chart never needs to be modified through .NET methods.
Bars and a target line on one chart, saved as WebP
New-ImageChart -XLabel Mon, Tue, Wed, Thu, Fri -FilePath latency.webp {
New-ImageChartBar -Name Requests -Value 410, 380, 455, 520, 470
New-ImageChartLine -Name 'p95 (ms)' -Value 182, 175, 240, 310, 205 -Marker Circle -SecondaryAxis
} -SecondaryYTitle 'p95 (ms)'Bar, line, area, scatter, and similar cartesian definitions can be mixed; markers and axes are set per series.
Parameters
- -Annotation Object[]
- Annotations for the chart.
- -AnnotationsDefinition ScriptBlock
- ScriptBlock producing annotations.
- -Background ChartColor
- Chart background color.
- -ChartsDefinition ScriptBlock
- ScriptBlock producing chart definitions.
- -Dpi Double
- PNG physical resolution metadata in dots per inch.
- -FilePath String
- The extension picks the format: .png, .svg, .html, or .htm use the ChartForgeX renderers; .jpg, .jpeg, .webp, .gif, .bmp, .tif, .tiff, and .tga encode the same pixels through ImagePlayground. Relative paths resolve against the current PowerShell location.
- -Height Int32
- Height of the chart in pixels.
- -Options ChartRenderOptions
- Renderer options created by New-ImageChartOptions.
- -PassThru SwitchParameter
- Write the ChartForgeX chart to the pipeline after rendering.
- -SecondaryYTitle String
- Title of the secondary (right) Y axis used by series created with -SecondaryAxis.
- -Show SwitchParameter
- Open the image after creation.
- -ShowGrid SwitchParameter
- Display grid lines.
- -Subtitle String
- Supporting chart heading. Supply an empty string to clear a supplied chart's subtitle.
- -Theme ChartTheme
- Chart theme.
- Possible values:
Default,Dark,Light,Colorblind,Aurora,Editorial,Candy,PeopleInfographic,Terminal,TransparentOverlayDark,Minimal,DashboardLight,SaasDashboardLight,RestaurantDashboardLight - -Title String
- Chart heading. A supplied native chart keeps its heading unless this parameter is supplied.
- -Watermark VisualWatermark[]
- Watermarks applied to static SVG, HTML, or PNG output.
- -Width Int32
- Width of the chart in pixels.
- -XLabel String[]
- Values at positions 1, 2, 3... of each series are labelled with these entries in order.
- -XTitle String
- X axis title.
- -YTitle String
- Y axis title.
- -ChartScript ScriptBlock
- The script block receives the chart as its first argument and can mutate it directly or return a replacement chart.
- -Chart Chart
- ChartForgeX chart object to render.
- -Definition ChartDefinition[]
- Typed definitions produced by New-ImageChart data cmdlets, supplied directly or through the pipeline.
Common Parameters
This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters.