Chart.Save Method

Saves a chart image to the specified file.

Namespace:  System.Web.Helpers
Assembly:  System.Web.Helpers (in System.Web.Helpers.dll)

public Chart Save(
	string path,
	string format
)

Parameters

path
Type: System.String
The location and name of the image file.
format
Type: System.String
The image file format, such as "png" or "jpeg".

Return Value

Type: System.Web.Helpers.Chart
The chart.

The following example shows how to render the chart image using the Save method.


@{ 
    var filePathName = "_ChartFiles/chart01.jpg"; 
    if (!File.Exists(Server.MapPath(filePathName))) { 
        var chartImage = new Chart(600, 400); 
        chartImage.AddTitle("Chart Title"); 
        chartImage.AddSeries( 
                name: "Employee", 
                axisLabel: "Name", 
                xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
                yValues: new[] { "2", "6", "4", "5", "3" }); 
        chartImage.Save(path: filePathName); 
    } 
}
<!DOCTYPE html> 
<html> 
    <head> 
        <title>Chart Example</title> 
    </head> 
    <body> 
        <img src="@filePathName" />  
    </body> 
</html>


  • Medium trust for the immediate caller. This member can be used by partially trusted code.
Show: