TeeChart Pro .Net汉化教程十:创建一个动态的WebChart

原创|其它|编辑:郝浩|2012-07-09 22:11:37.000|阅读 771 次

概述:参考TeeChart的TeeChartForNET中文版安装共享,里面有WebForm工作实例及C#.NET和VB.NET编写的ASP.NET实例。

# 界面/图表报表/文档/IDE等千款热门软控件火热销售中 >>

参考TeeChart的TeeChartForNET中文版安装共享,里面有WebForm工作实例及C#.NET和VB.NET编写的ASP.NET实例。

Web Form 实例

怎样创建一个动态的WebChart

  • 在你的服务器上创建一个新的WebForm应用程序,要确定该空白表单是否能正常运行。
  • 从Steema工具箱选项卡中,选择一个WebChart对象,将它拖放到WebForm中。
  • 选择新建的WebChart1对象,在属性窗口中找到TempChart属性,将其由File变为Session。这就意味着WebChart生成的所有的临时图表将被保存在一个session变量中而不是临时文件夹中(详见教程9 )
  • 为了恢复session变量中的临时图表,我们将在新的窗体中添加一些简单的代码。右键单击您的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);              
        }  
    }

  • 现在我们要接着编写一些基本的聚焦功能;在我们原有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;
    }

    运行代码,在气泡图上移动鼠标您就可以看到一系列标记的值,另外还有YValue.

  • 在图表中添加缩放功能,我们所要做的就是添加一个缩放工具和一些简单的代码来控制缩放状态:
    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在鼠标悬停时的行为。例如,我们希望点击气泡图上的一个点时,可以跳转到一个特定的网址;在图表中响应SeriesHotSpot事件并指向它的网址,通过设定MapAction属性是完全可以实现的,如下所示:

    在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为您提供了一些有用的内置scripts,并可以通过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中的参数来进行调用


(慧都控件网版权所有,转载请注明出处,否则追究法律责任)
标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@evget.com

文章转载自:慧都控件网

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP