惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 而且

参考网上例子,在PPT中批量设置m3的3为上标的VBA 分享自己动手弄的基于Rime的新世纪五笔输入法码表 快速设置IP的脚本 word中几个好用的宏代码(立方米上标、关闭样式自动更新、删除无效样式、表格加粗边框、宋体引号) word中设置首行缩进的快捷键 加密的encrypted.google.com不能访问的解决方法 - 而且 安装CASS后CAD的快捷键与工具栏恢复方法(含ctrl+z,复制、粘贴等) 在word2010里裁剪cad等图像 - 而且 解决奇妙的Dell显示器屏幕闪的问题 批量替换excel里的软回车 360,你还能再流氓一点吗? Google Earth批量生成地标文件(kml)的Excel VBA代码 - 而且 [转]Arcgis制作泰森多边形具体步骤 删除word中的参考文献引用标记 Aquaveo.GMS.v7.1.3.0.x86-REDT 修改的2010版word与excel的菜单,把常用的提取了出来 转一个按月统计的SQL语句 [转]如何让Firefox优化得比Chrome更快 [转]免费网站推广
amChart图形控件在asp.net中的使用
而且 · 2010-04-04 · via 博客园 - 而且

amChart控件是一套基于js+falsh的图形控件,折腾了两天,参考了网上前人总结的使用方法,终于基本能够使用了。顺便说一句,官网上的document实在是不太方便,也没有一个api的说明。

首先当然是添加对am.charts.dll的引用,可以添加到工具箱里,以后使用的时候直接把常用的5种图形按需要拖到web里。

添加数据的方式一种是写在一个cvs或xml文件里,不过这样对动态生态的图片实在是操作起来不太方便。通常通过后台添加数据,此次通过使用dropdownlist确定查询数据的ID,从而得到dataset,然后添加到amchart里,以linechart为例。具体代码如下,在DropDownList1_SelectedIndexChanged事件里:

 1         //清空原有图形
 2         LineChart1.Graphs.Clear();
 3         //准备数据
 4         //Response.Write(DropDownList1.SelectedValue + "," + DropDownList1.SelectedItem);
 5         string sql = "SELECT stcd,DATENAME(YEAR,tm)+DATENAME(MONTH,tm) as date,SUM(dyp) as dyp from ST_PPTN_R WHERE stcd='" +
 6             DropDownList1.SelectedValue +
 7             "' GROUP BY stcd,DATENAME(YEAR,tm)+DATENAME(MONTH,tm) ORDER BY stcd,date ";
 8         DataSet dataSet =
 9             SqlHelper.ExecuteDataset(
10                 ConfigurationManager.ConnectionStrings["RWDB"].ConnectionString, CommandType.Text,
11                 sql);
12         //添加数据线对象
13         LineChartGraph lineChartGraph = new LineChartGraph();
14         //顶点形状为正方形
15         lineChartGraph.Bullet = LineChartBulletTypes.Square;
16         //顶点颜色
17         //lineChartGraph.BulletColor = Color.Yellow;
18         //向下面积图的颜色
19         lineChartGraph.FillColor = Color.Yellow;
20         //向下面积图的透明度
21         lineChartGraph.FillAlpha = Convert.ToByte(40);
22         //添加数据
23         //Y轴值在右边(默认在左边)
24         //lineChartGraph.Axis = LineChartAxes.Right;
25         
26         lineChartGraph.DataSource = dataSet;//数据源
27         lineChartGraph.DataSeriesItemIDField = "date";//标识字段
28         lineChartGraph.DataValueField = "dyp";//值字段
29         lineChartGraph.Title = DropDownList1.SelectedItem.Text.Trim();//数据系列标题
30         //添加线条到图形
31         LineChart1.Graphs.Add(lineChartGraph);
32 
33         //添加平均值线条
34         double averagePre = 0;
35         int count = 0;
36         foreach (DataRow dataRow in dataSet.Tables[0].Rows)
37         {
38             if (dataRow["dyp"!= DBNull.Value)
39             {
40                 averagePre += Convert.ToDouble(dataRow["dyp"]);
41                 count++;
42             }
43         }
44         //Response.Write("average=" + averagePre.ToString() + ",count=" + count.ToString());
45         averagePre /= count;
46         averagePre = Math.Round(averagePre, 2);//保留两位小数
47         DataColumn dc_v = new DataColumn("average");//添加平均值的数据列到原dataset里
48         dataSet.Tables[0].Columns.Add(dc_v);
49         for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
50         {
51             dataSet.Tables[0].Rows[i][dc_v] = averagePre;
52         }
53         LineChartGraph lcg = new LineChartGraph();
54         lcg.DataSource = dataSet;
55         lcg.DataSeriesItemIDField = "date";
56         lcg.DataValueField = "average";
57         lcg.Title = "平均值";
58         LineChart1.Graphs.Add(lcg);
59         //添加Y轴单位说明
60         LineChart1.Labels.Add(new ChartLabel("mm",new Unit(30),new Unit(30))); //单位为mm
61         LineChart1.DataSource = dataSet;
62         LineChart1.DataSeriesIDField = "date";
63         LineChart1.DataBind();

几个需要注意的问题:

1.图形大小的设置

        //设置图形的宽高
        LineChart1.Width = new Unit(600);
        LineChart1.Height = new Unit(400);

 2.若不是采用dropdownlist等动态生成数据,web页面比较简单,没有重复生成图形的时候,可不用LineChart1.Graphs.Clear();来清空原图。若像我这样,每次通过点击dropdownlist来显示不同的数据的时候,需要加上LineChart1.Graphs.Clear()来清空原图,并且要设置linechart1的enableviewstate属性为false,否则会发现点击dropdownlist的时候显示的还是原来的数据,而且显示的数据不完整。这个问题折腾了我半天才发现。

3.数据绑定

  在lineChartGraph对象里要设置其 DataSource ,DataSeriesIDField ,DataValueField三个参数,但设置完了之后,在LineChart1里仍然需要设置其 DataSource ,DataSeriesIDField,否则显示不出图像。同样两个对象都需要DataBind()。
4.双坐标轴

  可以通过lineChartGraph.Axis = LineChartAxes.Right;来更改坐标轴的位置,通常默认在左边,当添加另一条线的时候可以设计其坐标轴在右边从而分开显示。

QQ截的图,显示的不太清楚,实际上flash的图片显示效果要好很多。