sql_sysquery
数据源
显示投票结果饼图,需要服务器支持XSLT编程标签方可使用
SELECT TOP 1 * FROM PE_Vote WHERE GeneralID = @itemId
double curValue = 0;
string preColor = "rgb(0,0,0)";
double mX = Math.Pow(2,16) * 360;
int rocount = 1;
int Socount = 1;
private string startAngle(string vValue, string nnum)
{
double svalue = Convert.ToDouble(vValue) / Convert.ToDouble(nnum);
double preValue = curValue;
curValue += svalue;
return Convert.ToInt32(mX * preValue).ToString();
}
private string endAngle(string vValue, string nnum)
{
double svalue = Convert.ToDouble(vValue) / Convert.ToDouble(nnum);
return Convert.ToInt32(mX * svalue).ToString();
}
public string getheight(int vValue)
{
int a = 1200 * vValue + 1000;
return a.ToString();
}
public string randomColor()
{
Random rn = new Random(unchecked(rocount * (int)DateTime.Now.Ticks));
Random gn = new Random(unchecked(rocount * (int)DateTime.Now.Ticks) + Socount * 9);
Random bn = new Random(unchecked(rocount * (int)DateTime.Now.Ticks) + Socount * 21);
preColor = "rgb(" + rn.Next(0,255) + "," + gn.Next(0,255) + "," + bn.Next(0,255) + ")";
rocount++;
Socount += 5;
return preColor;
}
public string ShowVoteImage(string ostr, string otitle)
{
XmlDocument xmldoc = new XmlDocument();
try
{
xmldoc.LoadXml(ostr);
}
catch (XmlException e)
{
return e.Message;
}
int i = 1;
Decimal totalnum = Convert.ToDecimal(GetVoteNum(ostr));
string outstr = "<![CDATA[<v:group coordsize='21600,21600' " + "style='width:640px;height:450px'" + ">";
outstr += "<v:rect style='width:21600px;height:21600px' fillcolor='#e6e6e6'>";
outstr += "<v:textbox style='text-Align:center;font-size:24px;font-Weight:bold;height:24px'>" + otitle + "</v:textbox></v:rect>";
outstr += "<v:shadow on='t'/>";
foreach (XmlNode inode in xmldoc.DocumentElement.ChildNodes)
{
XmlElement rnode = (XmlElement)inode;
if (!string.IsNullOrEmpty(rnode.GetAttribute("Title")))
{
outstr += "<v:shape style='width:11000px;height:14000px;top:4000px;left:1000px' adj='0,0' strokecolor='window' coordsize='1500,1400'";
outstr += " path='M 750 700 AE 750 700 750 700 " + startAngle(rnode.GetAttribute("VoteNumber"), GetVoteNum(ostr)) + " " + endAngle(rnode.GetAttribute("VoteNumber"), GetVoteNum(ostr)) + "xe'";
outstr += " fillcolor='" + randomColor() + "'";
outstr += " title='" + rnode.GetAttribute("Title") + "'/>";
outstr += "<v:rect style='left:14000px;width:600px;height:800px;top:" + getheight(i) + "px'";
outstr += " fillcolor='" + preColor + "'/>";
outstr += "<v:rect strokecolor='black'";
outstr += " style='left:14500px;top:" + getheight(i) + "px'>";
outstr += "<v:textbox style='font:caption'>" + rnode.GetAttribute("Title") + "(" + rnode.GetAttribute("VoteNumber") + ")</v:textbox>";
outstr += "</v:rect>";
i += 1;
}
}
outstr += "</v:group>]]>";
return outstr;
}
public string GetVoteNum(string ostr)
{
XmlDocument xmldoc = new XmlDocument();
try
{
xmldoc.LoadXml(ostr);
}
catch (XmlException e)
{
return e.Message;
}
int i = 0;
foreach (XmlNode inode in xmldoc.DocumentElement.ChildNodes)
{
XmlElement rnode = (XmlElement)inode;
if (!string.IsNullOrEmpty(rnode.GetAttribute("Title")))
{
i += Convert.ToInt32(rnode.GetAttribute("VoteNumber"));
}
}
return i.ToString();
}
]]>
itemId
1
投票ID
0
False
false
false