【TeeChart .NET教程】(十)Web表单示例

【下载TeeChart.Net最新版本】

Web表单示例

如何创建动态WebChart
  • 在服务器上创建一个新的WebForm应用程序,并确保它在表单上没有任何内容正确运行。
  • 从Steema ToolBox选项卡中,选择一个WebChart对象并将其拖动到WebForm上。
  • 选择新的WebChart1对象,然后在“Properties ”窗口中导航到TempChart属性并将其从“File ”更改为“Session”。这意味着WebChart生成的所有临时图表都将存储在会话变量中,而不是存储在临时文件夹中。
  • 为了从会话变量中恢复临时图表,添加一个新的表单,其中包含一些简单的代码。右键单击ASP.NET项目并添加一个新的WebForm,命名为GetChart.aspx。现在确保Page_Load事件如下所示:
    private void Page_Load(object sender, System.EventArgs e){     string chartName=Request.QueryString["Chart"];            if (Session[chartName]!=null)          {                  System.IO.MemoryStream chartStream = new System.IO.MemoryStream();              chartStream=((System.IO.MemoryStream)Session[chartName];                  Response.OutputStream.Write(chartStream.ToArray(),0,(int)chartStream.Length);                  chartStream.Close();                  Session.Remove(chartName);          } } 
  • 继续生成一些基本的HotSpot功能; 在原始WebForm的Form_Load事件中,可以添加类似于以下内容的代码:
    private void Page_Load(object sender, System.EventArgs e){     //Let's work with the Chart object for convenience     Steema.TeeChart.Chart Chart1 = WebChart1.Chart;     //Add in a series and fill it     Chart1.Aspect.View3D = false;     Steema.TeeChart.Styles.Bubble bubble1 = new Steema.TeeChart.Styles.Bubble(Chart1);     bubble1.FillSampleValues();     //Add a SeriesToolTip to the Chart     Steema.TeeChart.Tools.SeriesHotspot seriesHotSpot1 = new Steema.TeeChart.Tools.SeriesHotspot(Chart1);     //Steema.TeeChart.Styles.MapAction.Mark is the default value     seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.Mark;}
  • 要向图表添加缩放功能,我们需要做的就是添加一个zoomtool和一些简单的代码来控制缩放状态:
    private void Page_Load(object sender, System.EventArgs e){     //Let's work with the Chart object for convenience     Steema.TeeChart.Chart Chart1 = WebChart1.Chart;     //Add in a series and fill it     Chart1.Aspect.View3D = false;     Steema.TeeChart.Styles.Bubble bubble1 = new Steema.TeeChart.Styles.Bubble(Chart1);     bubble1.FillSampleValues();     //Add a SeriesToolTip to the Chart     Steema.TeeChart.Tools.SeriesHotspot seriesHotSpot1 = new Steema.TeeChart.Tools.SeriesHotspot(Chart1);     //Steema.TeeChart.Styles.MapAction.Mark is the default value     seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.Mark;     //Add a ZoomTool to the Chart     Steema.TeeChart.Tools.ZoomTool zoomTool1 = new Steema.TeeChart.Tools.ZoomTool(Chart1);     // *************** Code for zoom support ***************     //check whether zoom request is being sent     CheckZoom(WebChart1);}private void CheckZoom(WebChart wChart){     ArrayList zoomedState=(ArrayList)Session[wChart.ID+"Zoomed"];     zoomedState=((Steema.TeeChart.Tools.ZoomTool)wChart.Chart.Tools[0]).SetCurrentZoom(Request,zoomedState);     if (zoomedState==null)        Session.Remove(wChart.ID+"Zoomed");     else        Session.Add(wChart.ID+"Zoomed",zoomedState);}
  • 有一个交互式图表,可响应鼠标悬停和鼠标点击事件。SeriesHotSpot(在这种情况下与气泡系列相关联)将在鼠标移过它时显示系列标记的值。但是,通过MapAction属性,我们可以在鼠标移过它时自定义SeriesHotSpot的行为。例如,我们可能希望点击其中一个气泡将我们带到指定的URL; 通过将MapAction属性设置为URL,链接SeriesHotSpot事件并在其中指定URL,在Page_Load事件中:
    seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.URL;seriesHotSpot1.GetHTMLMap += new Steema.TeeChart.Tools.SeriesHotspotEventHandler(seriesHotSpot1_GetHTMLMap);
  • GetHTMLMap方法:
    private void seriesHotSpot1_GetHTMLMap(Steema.TeeChart.Tools.SeriesHotspot sender, Steema.TeeChart.Tools.SeriesHotspotEventArgs e) {     e.PointPolygon.Title = "Go to the Steema web";     e.PointPolygon.HREF = "http://www.steema.com";     e.PointPolygon.Attributes = "target='_blank'";}
  • 有效地将MapAction属性设置为Script允许用户定义任何事件,TeeChart为用户提供了一些有用的内置脚本,可以通过HelperScripts枚举来调用。例如,要在鼠标悬停在其中一个气泡序列点上时打开图像文件,我们将添加以下代码,在Page_Load事件中:
    seriesHotSpot1.MapAction = Steema.TeeChart.Styles.MapAction.Script;seriesHotSpot1.HelperScript = Steema.TeeChart.Tools.HotspotHelperScripts.Annotation;
  • 这里的第二行确保将相关的JavaScript添加到客户端浏览器中,GetHTMLMap方法:
    private void seriesHotSpot1_GetHTMLMap(Steema.TeeChart.Tools.SeriesHotspot sender, Steema.TeeChart.Tools.SeriesHotspotEventArgs e) {     e.PointPolygon.Attributes=String.Format(Steema.TeeChart.Texts.HelperScriptAnnotation, "【TeeChart .NET教程】(十)Web表单示例");}

进一步自定义行为意味着设计自定义的JavaScript例程,将它们添加到客户端浏览器,然后通过将它们及其参数添加到e.PointPolygon.Attributes来调用它们。

标签:图表Web图表teechart

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2018年7月6日
下一篇 2018年7月6日

相关推荐

发表回复

登录后才能评论