I am getting this error
Invalid temp directory in chart handler configuration [c:\\TempImageFiles\\].
While running my code.
Intially I was getting
You can circumvent temporary image caching by using BinaryStreaming.
Google should do the rest.
It worked for me on Linux, where it threw an InvalidDirectory Exception for Linux paths.
(RenderType="BinaryStreaming")
Codebehind:
protected void Page_Load(object sender, EventArgs e)
{
FillChartFromDataBase();
}
public void FillChartFromDataBase()
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Area", typeof(double));
table.Columns.Add("Label", typeof(string));
System.Data.DataRow row = table.NewRow();
row["Area"] = 791;
row["Label"] = "HNF 1";
table.Rows.Add(row);
row = table.NewRow();
row["Area"] = 978;
row["Label"] = "HNF 2";
table.Rows.Add(row);
row = table.NewRow();
row["Area"] = 1262;
row["Label"] = "HNF 3";
table.Rows.Add(row);
row = table.NewRow();
row["Area"] = 1650;
row["Label"] = "HNF 4";
table.Rows.Add(row);
row = table.NewRow();
row["Area"] = 2519;
row["Label"] = "HNF 5";
table.Rows.Add(row);
row = table.NewRow();
row["Area"] = 6071;
row["Label"] = "HNF 6";
table.Rows.Add(row);
// Set chart custom palette
ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;
//ChartDIN277.PaletteCustomColors = New System.Drawing.Color() {System.Drawing.Color.Red, System.Drawing.Color.Blue}
ChartDIN277.PaletteCustomColors = COR.Design.ColorPalette.Generate(System.Drawing.Color.ForestGreen, table.Rows.Count - 1);
// http://student.csdn.net/space.php?uid=383581&do=blog&id=32768
//ChartDIN277.Palette = System.Web.UI.DataVisualization.Charting.ChartColorPalette.None;
//ChartDIN277.PaletteCustomColors = new Color[] { System.Drawing.Color.Red, System.Drawing.Color.Blue};
//// Hide all series empty data point by making them transparent
//Chart.Series[0].EmptyPointStyle.Color = Color.Transparent;
//// Set color for the whole series
//Chart.Series[0].Color = Color.Green;
//// Set color of a single data point
//Chart.Series[0].Points[5].Color = Color.Red;
this.ChartDIN277.DataSource = table;
this.ChartDIN277.DataBind();
}
or create an ashx handler, like this
Imports System.Web
Imports System.Web.Services
Public Class ChartCreator
Implements System.Web.IHttpHandler
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.ContentType = "image/jpeg"
Dim yValues As Double() = {10, 27.5, 7, 12, 45.5}
Dim xNames As String() = {"Mike", "John", "William", "George", "Alex"}
Dim mychart As System.Web.UI.DataVisualization.Charting.Chart
mychart = New System.Web.UI.DataVisualization.Charting.Chart
Dim mychartarea As New System.Web.UI.DataVisualization.Charting.ChartArea()
mychartarea.Name = "ChartArea1"
mychartarea.BackColor = Drawing.Color.Transparent
mychart.ChartAreas.Add(mychartarea)
Dim myseries As New System.Web.UI.DataVisualization.Charting.Series()
myseries.ChartArea = mychartarea.Name
myseries.ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie
myseries.Name = "Series1"
mychart.Series.Add(myseries)
mychart.BackColor = Drawing.Color.Transparent
mychart.Series(0).Points.DataBindXY(xNames, yValues)
mychart.Series(0).Points.DataBindXY(xNames, yValues)
' http://msdn.microsoft.com/en-us/library/system.web.ui.datavisualization.charting.rendertype.aspx
' ImageTag, BinaryStreaming, ImageMap
' mychart.RenderType = System.Web.UI.DataVisualization.Charting.RenderType.BinaryStreaming
mychart.ImageType = System.Web.UI.DataVisualization.Charting.ChartImageFormat.Png
'mychart.SaveImage(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "mychart.png"))
mychart.SaveImage(context.Response.OutputStream)
'getResizedImage(context.Request.PhysicalPath,Width,Height);
'context.Response.OutputStream
context.Response.End()
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class