程序员的知识教程库

网站首页 > 教程分享 正文

「TeeChart Pro ActiveX教程」(十):演示ASP示例

henian88 2024-08-27 15:41:29 教程分享 5 ℃ 0 评论

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。 要向图表添加缩放功能,我们需要做的就是添加一个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, "<IMG SRC=Images/myimage.jpg>"); 
} 

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

点击了解更多下载产品最新版

↓↓↓

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表