Chart.WriteFromCache Method

Renders the output of a Chart object that has been cached as an image.

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

public static Chart WriteFromCache(
	string key,
	string format
)

Parameters

key
Type: System.String
The ID of the chart in the cache.
format
Type: System.String
The format of the image. The default is "jpeg".

Return Value

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

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


@{ 
    var chartKey = Request["key"]; 
    if (chartKey != null) { 
        var cachedChart = Chart.GetFromCache(key: chartKey); 
        if (cachedChart == null) { 
            cachedChart = new Chart(600, 400); 
            cachedChart.AddTitle("Cached Chart -- Cached at " + DateTime.Now); 
            cachedChart.AddSeries( 
               name: "Employee", 
               axisLabel: "Name", 
               xValue: new[] { "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
               yValues: new[] { "2", "6", "4", "5", "3" }); 
            cachedChart.SaveToCache(key: chartKey,  
               minutesToCache: 2,  
               slidingExpiration: false); 
        } 
        Chart.WriteFromCache(chartKey); 
    } 
}


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