c#.net结合vml与js生成web曲线通用类

将前面的asp+vml动态实现网页曲线图二重新用c#.net包装成了方法,只需要直接传递参数就可以生成曲线了,这样对动态生成曲线很方便,前面已经写成了asp调用方法.这个同样依赖前面文章的4.css和4.js,需要的话请自己浏览查找.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using quxiantu;
namespace quxiantu
{
 /// <summary>
 /// WebForm1 的摘要说明。
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {

  //曲线和点的颜色
  protected string[] colorArr = new string[11] {"#ff6600","#ff1188","#ff66dd","#ff0033","#ff9900","#ffdd00","#007700","#777700","#dd6600","#dd0000","#44cc00"};

  private string title = "曲线图";      //曲线名字
  public string Title
  {
   get {return title;}
   set {if (value != title) title = value;}
  }
  private string xunit = "x单位";
  protected System.Web.UI.WebControls.Button Button1;
       //x轴单位
  public string Xunit
  {
   get {return xunit;}
   set {if (value != xunit) xunit = value;}
  }
  private string yunit = "y单位";      //y轴单位
  public string Yunit
  {
   get {return yunit;}
   set {if (value != yunit) yunit = value;}
  }
  

  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  #region 写javascript语句内容,<script language=javascript></script>已经写好。
  public void Echo(string str)
  {
   HttpContext Context=HttpContext.Current;
   Context.Response.Write(str);
  }
  #endregion

  private void qx2(string xzuobiao,string yzuobiao,int xper,int xmin,int yper,int ymin,ArrayList xvalue,string valuetip,ArrayList yvalue)
  {
   Echo("<HTML xmlns:v=/"urn:schemas-microsoft-com:vml/" xmlns:o=/"urn:schemas-microsoft-com:office:office/">");
   string str_table="<table align=/"center/" border=/"0/" cellpadding=/"0/" cellspacing=/"0/" width=/"100%/"><tr><td height=/"20/"><div align=/"center/" id=/"curve/"></div></td></tr></table>";
   
   Echo("<link rev=/"stylesheet/" media=/"all/" href=/"4.css/" type=/"text/css/" rel=/"stylesheet/">/n <script src=/"4.js/" language=/"javascript/"></script>/n");
   Echo (str_table);
   Echo("/n<script language=javascript>/n<!--/n var vc = new VMLCurve(document.all.curve);");
   //x,y坐标
   Echo("/n vc.configXValue = new Array("+xzuobiao+")");
   Echo("/nvc.configYValue = new Array("+yzuobiao+");");
   //x,y坐标间距和最小值
   Echo("/nvc.configXPerValue = "+xper+";/nvc.configXMinValue = "+xmin+";/nvc.configYPerValue = "+yper+";/nvc.configYMinValue = "+ymin+";");
   //曲线名称等
   Echo("/nvc.init(/"vc/",/""+title+"/",/""+xunit+"/",/""+yunit+"/");");
   //点提示信息
   Echo("/nvar sValueArr = new Array("+valuetip+");");
   for(int i=0;i<xvalue.Count;i++)
   {
    //x坐标值
    Echo("/nvar xValueArr"+i+" = new Array("+xvalue[i]+");");
   
    //y轴值
    Echo("/nvar yValueArr"+i+" = new Array("+yvalue[i]+");");
    Echo("/nvc.setPointsProp(2,1,'"+colorArr[i]+"','"+colorArr[i]+"');/n vc.setPointsValue(xValueArr"+i+",yValueArr"+i+",sValueArr);");
   }
   Echo("/n//-->/n</script>");

  }
  private void Button1_Click(object sender, System.EventArgs e)
  {
   test2();
  }
  private void test2()
  {
   string xzuobiao="'一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'";
   string yzuobiao="'100','200','300','400','500','600','700','800','900','1000'";
   string valuetip="'第1个点','第2个点','第3个点','第4个点','第5个点','第6个点','第7个点','第8个点','第9个点','第10个点','第11个点','第12个点'";
   ArrayList xvalue=new ArrayList();
   xvalue.Add("1,2,3,4,5,6,7,8,9,10,11,12");
   xvalue.Add("1,1.3,2,2.4,3,4,5,5.5,7,8,9,10,11,12");
   ArrayList yvalue=new ArrayList();
   yvalue.Add("320,280,420,550,600,700,800,720,190,940,590,340");
   yvalue.Add("350,280,220,410,480,580,680,780,880,880,180,840,580,380");
  qx2(xzuobiao,yzuobiao,1,1,200,200,xvalue,valuetip,yvalue);
  }
 }

web页上绘制饼图曲线图等组件(c#) 例子: 生成饼图表******************************************** private void InitializeComponent() { this.myBarGraph.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraphBar); this.myLineGraph.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraphLine); } private void OnRenderGraphBar(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane) { myBarMethod(zgw, g, masterPane, strYear, strMonth, compareType); } private void OnRenderGraphLine(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane) { myLineMethod(zgw, g, masterPane, douYear, douMonth); } private void myBarMethod(ZedGraphWeb zgw, System.Drawing.Graphics g, ZedGraph.MasterPane masterPane, string[] strYear, string[] strMonth, string compareType) { GraphPane myPane = masterPane[0]; myPane.Title.Text = title + "柱状图分析"; myPane.XAxis.Title.Text = "时间(月/年)"; if (compareType == "AddValue") { myPane.YAxis.Title.Text = "增加值"; } else { myPane.YAxis.Title.Text = "增加比例(%)"; } List<PointPairList> ListPointParitList = new List<PointPairList>(); for (int i = 0; i < strYear.Length; i++) { ListPointParitList.Add(new PointPairList()); } int n = 0; for (double x = 0; x < strMonth.Length; x += 1.0) { for (int i = 0; i < strYear.Length; i++) { //ListPointParitList[i].Add(x, randNum[n++] * multiplyValue); ListPointParitList[i].Add(x, GetFXData(strYear[i], strMonth[(int)x])); } } List<BarItem> ListBarItem = new List<BarItem>(); List<Color> ListColor = GetColor(); for (int i = 0; i < strYear.Length; i++) { ListBarItem.Add(new BarItem(strYear[i], ListPointParitList[i], ListColor[i])); ListBarItem[i] = myPane.AddBar(strYear[i], ListPointParitList[i], ListColor[i]); } myPane.XAxis.MajorTic.IsBetweenLabels = true; myPane.XAxis.Scale.TextLabels = strMonth; myPane.XAxis.Type = AxisType.Text; myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f); myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f); masterPane.AxisChange(g); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值