热门IT资讯网

js图表控件:highcharts的应用(二)

发表于:2024-11-27 作者:热门IT资讯网编辑
编辑最后更新 2024年11月27日,柱状图前台代码:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="zhuxingtu2.aspx.cs" Inherits="hhh.

柱状图

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="zhuxingtu2.aspx.cs" Inherits="hhh.zhuxingtu2" %>


















后台代码:

public string str = "";//数据
public string strtxt = "[";//文本
public string strtxt1 = "";
public int m = 0;
public double allcount=0;
protected void Page_Load(object sender, EventArgs e)
{
LoadData();
Result();
}
protected void LoadData()
{
XmlDocument myDoc = new XmlDocument();
myDoc.Load(Server.MapPath("DB_51aspx.xml"));

XmlNode xn = myDoc.SelectSingleNode("//VoteInfo[ID='2']");//读取数据源

XmlNodeList xnl = xn.SelectNodes("Item");
m = xnl.Count;
double AllCount = 0;//总数

for (int i = 0; i < xnl.Count; i++)
{
AllCount += Convert.ToSingle(xnl.Item(i).SelectSingleNode("Count").InnerText);
}


allcount = AllCount;


for (int i = 0; i < xnl.Count; i++)
{
XmlNode xn0 = xnl.Item(i);
str+=xn0.SelectSingleNode("Count").InnerText+",";
strtxt += "\'" + xn0.SelectSingleNode("Title").InnerText + "\'" + ",";
strtxt1 += "\'" + xn0.SelectSingleNode("Title").InnerText + "\'" + ",";
}

str = str.Remove(str.Length - 1, 1);//数据
strtxt = strtxt.Remove(strtxt.Length - 1, 1);//文本
strtxt += "]";
strtxt1 = strtxt1.Remove(strtxt1.Length-1,1);
}
public string Result()
{
string datastr = "";
string[] arr = str.Split(',');
string[] arr2 = strtxt1.Split(',');
for (int i = 0; i < arr.Length; i++)
{
datastr += "{" + "y:" + Convert.ToDecimal(arr[i].ToString()) + "," + "color:colors[" + i + "]," + "drilldown: {name:" + arr2[i].ToString() + ",color:colors[" + i + "]}},";
}
datastr = datastr.Remove(datastr.Length - 1, 1);
return datastr;
}

效果图展示:

xml数据源:




2


1
全站源码
110


2
新闻文章
20


3
博客论坛
123


4
影音视频
28


5
上传下载
100


6
功能源码
100


7
投票调查
200


8
聊天计数
140


9
行政办公
180


10
天龙八部
200


11
神雕侠侣
200


12
碧血剑
200


13
王重阳
100


14
张无忌至武当山
100


15
张三丰
100


16
张翠山
5


17
金毛狮王
1


18
紫衫龙王
2


19
紫衫龙王2
6


20
紫衫龙王3
1


20
紫衫龙王4
1


20
紫衫龙王5
1


20
紫衫龙王6
1


0