Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 1896

Summary: Advisory. When using TeeChart in an MVC ActionResult duplicate hash id error occurs during multi-access
Product: .NET TeeChart Reporter: marc meumann <marc>
Component: ExportingAssignee: Steema Issue Manager <issuemanager>
Status: RESOLVED FIXED    
Severity: normal    
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Chart Series: --- Delphi / C++ Builder RAD IDE Version:

Description marc meumann 2017-07-21 04:13:58 EDT
TeeChart being rendered in export in MVC application in image format (eg PNG, JPEG). During simultaneous access duplicate hash id key error is generated.

This occurs in the Canvas paint code and relates to generic limitations of multiple access in GDI+.


The problem  has workarounds. You can turn off use of the cache for improvements.
ie.
Steema.TeeChart.Utils.UseCaches = false;

But the recommended way to use TeeChart as an MVC component, for multiple simultaneous access, is to add a lock around the Chart rendering code.

eg.
==========
private static Object renderLock = new Object();

public void GetChart()
{
  lock (renderLock)
  {
    Steema.TeeChart.Web.WebChart wChart = new Steema.TeeChart.Web.WebChart();

    //Steema.TeeChart.Utils.UseCaches = false;

    wChart.Chart.Series.Add(new Steema.TeeChart.Styles.Line());
    wChart.Chart.Series[0].FillSampleValues();

    tempStream1 = new System.IO.MemoryStream();
    wChart.Chart.Export.Image.PNG.Save(tempStream1);
    tempStream1.Flush();
    Response.ContentType = "Image/PNG";
    Response.OutputStream.Write(tempStream1.ToArray(), 0, (int)tempStream1.Length);

    tempStream1.Close();
  }
}
=======
or
=======
public ActionResult GetHTML5Chart(int? number) {

lock (renderLock)
{
  Steema.TeeChart.Web.WebChart wChart3 = new Steema.TeeChart.Web.WebChart();

  if (number==0)
    wChart3.Chart.Series.Add(new Steema.TeeChart.Styles.Pie());
  else if (number==1)
    wChart3.Chart.Series.Add(new Steema.TeeChart.Styles.Bar());
  else
    wChart3.Chart.Series.Add(new Steema.TeeChart.Styles.Line());
  wChart3.Chart.Series[0].FillSampleValues();

  string[] customCode = new string[] {

          " chart1.applyTheme(\"minimal\");" };

  wChart3.Chart.Export.Image.JScript.CustomCode = customCode;

  tempStream2 = new System.IO.MemoryStream();
  wChart3.Chart.Export.Image.JScript.Width = 900;
  wChart3.Chart.Export.Image.JScript.Height = 300;
  wChart3.Chart.Export.Image.JScript.Save(tempStream2);

  tempStream2.Position = 0;

  System.IO.StreamReader sr = new System.IO.StreamReader(tempStream2);

  return Content(sr.ReadToEnd());
}
==========