TeeChart Pro .NET使用教程(2022):演示ASP 示例

此次 表开发工具TeeChart Pro .NET使用教程将为大家带来演示ASP 示例。

Web 表单示例
如何创建动态 WebChart

在您的服务器上创建一个新的 WebForm 应用程序,并确保它在表单上没有任何内容的情况下正确运行。

从 Steema ToolBox 选项卡中,选择一个 WebChart 对象并将其拖过 WebForm。

选择新的 WebChart1 对象并在“属性”窗口中导航到 TempChart 属性并将其从“文件”更改为“会话”。 这意味着由 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;}

执行此代码并将鼠标移到气泡上将显示系列标记的值,在本例中为 YValues。

要为图表添加缩放功能,我们需要做的就是添加一个缩放工具和一些简单的代码来控制缩放状态:

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);}

我们现在有一个响应 mouseover 和 mouseclick 事件的交互式图表。 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, "IMG SRC=Images/myimage.jpg>");}

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


如果您想了解TeeChart for .NET正版价格,欢迎咨询在线客服

TeeChart Pro .NET使用教程(2022):如何进行ADO 数据库访问
标签:

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

上一篇 2022年1月27日
下一篇 2022年1月27日

相关推荐

发表回复

登录后才能评论