Framework / Thin Web / Common Server Settings
In This Topic
    Common Server Settings
    In This Topic

    Both the Chart and Diagram ThinWeb controls expose a ServerSettings object that allows you to configure automatic update and how the images served to the client.

     Automatic Update

    Automatic update allows you to instruct the control to initiate an AJAX update on a specified time interval. This is especially useful when you build web applications that monitor real time data. In order to configure automatic update you need to do the following:

    1. Set the EnableAutoUpdate property of the ServerSettings object to true.

    2. Optionally modify the AutoUpdateInterval.

    3. Register an AutoUpdate callback.

    The following code snippets show how to automatically update a label in the Chart and the Diagram ThinWeb controls so that it shows the current server time:

    Nevron Chart ThinWeb

    C#
    Copy Code

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!NThinChartControl1.Initialized)

    {

    // clear the chart
    NThinChartControl1.Panels.Clear();

    // add a label with the current time
    NLabel
    label = new NLabel(DateTime.Now.ToString());
    NThinChartControl1.Panels.Add(label);
    NThinChartControl1.AutoUpdateCallback =
    new ChartAutoUpdateCallback();

    // enable auto update
    NThinChartControl1.ServerSettings.EnableAutoUpdate = true;
    // refresh every second
    NThinChartControl1.ServerSettings.AutoUpdateInterval = 1000;
    }

    }

    [Serializable]
    class ChartAutoUpdateCallback : INAutoUpdateCallback
    {

    #region INAutoUpdateCallback Members

    public void OnAutoUpdate(Nevron.ThinWeb.NAspNetThinWebControl control)
    {
    NThinChartControl chartControl = (NThinChartControl)control;
    chartControl.Labels[0].Text =
    DateTime.Now.ToString();
    chartControl.UpdateView();
    }

    public void OnAutoUpdateStateChanged(Nevron.ThinWeb.NAspNetThinWebControl control)

    {

    }

    #endregion}

    Nevron Diagram ThinWeb

    C#
    Copy Code

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!NThinDiagramControl1.Initialized)
    {

    // init the document
    NDrawingDocument document = NThinDiagramControl1.Document;
    document.BeginInit();
    document.BackgroundStyle.FrameStyle.Visible =
    false;
    document.AutoBoundsPadding =
    new Nevron.Diagram.NMargins(10f, 10f, 10f, 10f);
    document.Style.FillStyle =
    new NColorFillStyle(Color.White);
    NTextShape timeShape = new NTextShape(DateTime.Now.ToString(), new NRectangleF(0, 0, 200, 50));
    document.ActiveLayer.AddChild(timeShape);
    NThinDiagramControl1.SizeToContent();
    NThinDiagramControl1.AutoUpdateCallback =
    new DiagramAutoUpdateCallback();

    // enable auto update
    NThinDiagramControl1.ServerSettings.EnableAutoUpdate = true;
    // refresh every second
    NThinDiagramControl1.ServerSettings.AutoUpdateInterval = 1000;
    }

    }

    [Serializable]
    class DiagramAutoUpdateCallback : INAutoUpdateCallback
    {

    #region INAutoUpdateCallback Members

    public void OnAutoUpdate(Nevron.ThinWeb.NAspNetThinWebControl control)
    {

    NThinDiagramControl diagramChontrol = (NThinDiagramControl)control;
    NTextShape textShape = (NTextShape)diagramChontrol.Document.ActiveLayer.GetChildAt(0);
    textShape.Text =
    DateTime.Now.ToString();
    diagramChontrol.UpdateView();

    }

    public void OnAutoUpdateStateChanged(Nevron.ThinWeb.NAspNetThinWebControl control)
    {

    }

    #endregion

    }

    All callbacks that you register must be marked as Serializable, because they are persisted with the controller in the control session state.
     Image Response Mode

    The image response mode allows you to configure how raster images generated by the control are served to the client. The following table lists the available options:

    ImageResponseMode Description
    Request Images are served in a separate request. This mode results in slower processing, but is supported by all browsers.
    Embed Images are embedded in the AJAX response. This mode results in faster processing, but with slightly bigger traffic. Base 64 encoded images are not fully supported by IE browsers less than version 9.0. 
    Auto The control will automatically decide whether to embed the image based on the detected browser accessing the control. This is the default.

    The following code snippet shows how to switch the ImageResponseMode to Serve:

    C#
    Copy Code

    thinControl.ServerSettings.ImageServeMode = ImageServeMode.Request;

    Visual Basic
    Copy Code
     

    thinControl.ServerSettings.ImageServeMode = ImageServeMode.Request

     Error Messages

    By default the control will display error messages for exceptions that occured on the server - that helps track problems that arise during control request processing. If you wish to turn off error messages you need to set the DisplayErrorMessages property to false:

    C#
    Copy Code

    thinControl.ServerSettings.DisplayErrorMessages = false;

    Visual Basic
    Copy Code

    thinControl.ServerSettings.DisplayErrorMessages = False

     Tile Cache Size

    The TiledCacheSize property controls the maximum number of pixels in the that the control can cache on the client in the x and y direction. By default this property is set to 2000 pixels. To better understand the meaning of this property consider the following situation - if the user zooms in a chart with plot size of 400x200 pixels with a zoom factor of 10 this results in a virtual image of size 4000x2000 pixels. This image will be partitioned and only the visible tiles will be send to the client. When the user scrolls the currently visible viewport (which is still 400x200 pixels), tiles that are currently not present on the client will be requested from the server. The control keeps track of tiles that are not currently visible but loaded on the client, when the size of these tiles exceeds the value of this property they will be discarded.

    It is important not to set too large values to this property as this can result in large memory usage on the client. Values in the range 1000-4000 produce optimal results. The following code shows how to extend the amount of cache size on the client:

    C#
    Copy Code

    NThinChartControl1.ServerSettings.TileCacheSize = 3000;

    Visual Basic
    Copy Code

    NThinChartControl1.ServerSettings.TileCacheSize = 3000

     

    Some Text

     Related Examples

    Nevron Chart\Web Forms\ThinWeb\Auto Update
    Nevron Chart\Mvc\ThinWeb\Auto Update

    Nevron Diagam\Web Forms\ThinWeb\Auto Update
    Nevron Diagam\Mvc\ThinWeb\Auto Update