TeeChart for .NET图表控件教程:ASP.NET网络表格实例

本文介绍TeeChart图表ASP.NET网络表格实例 ,及如何创建一个动态的WebChart 。

TeeChart for .NET是优秀的 4.0 WinForm 图表控件,官方独家授权汉化,集功能全面、性能稳定版、优惠等优势。NET 的 TeeChart for .NET 中文承诺让您在使用和学习上没有语言障碍,最少可以节省 30% 的开发时间。

点击立即下载最新版TeeChart for .NET

网络表格实例 

请参阅与TeeChart一起安装的TeeChartForNET虚拟共享,了解WebForm的工作实例以及用C#.NET和VB.NET编写的其他ASP.NET实例。

网络表格实例

如何创建一个动态的WebChart 

  • 在你的服务器上创建一个新的WebForm应用程序,并确保它在表单上没有任何东西的情况下正常运行。
  • 从Steema ToolBox标签,选择一个WebChart对象并将其拖到WebForm上。
  • 选择新的WebChart1对象,在属性窗口中导航到TempChart属性并将其从文件改为会话。这意味着由WebChart生成的所有临时图表将被存储在会话变量中,而不是临时文件夹中(更多细节见教程9)。
  • 为了从会话变量中恢复临时图表,我们将在一个新的表单中加入一些简单的代码。右击你的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属性设置为脚本可以有效地让你定义任何你喜欢的行为。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已加入在线订购,现在抢购可立享优惠!

如果您对该图表控件感兴趣,欢迎加入图表控件QQ交流群:

关注慧聚IT微信公众号了解产品的最新动态及最新资讯。

标签:

来源:慧都

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年6月17日
下一篇 2021年6月17日

相关推荐

发表回复

登录后才能评论