关于webchart这个图标控件的使用,近期稍微研究了下,也使用率一些功能,做个记录分享下,前端加个控件
<Web:ChartControl Legend-Position="Bottom" Padding="20" Width="1000px" Height="500px" ID="ChartControl1" runat="server" GridLines="None" HasChartLegend="true">
<ChartTitle Text="需求完成记录" StringFormat="Near,Near,Character,LineLimit" Font="Verdana, 10pt, style=Bold" ForeColor="DeepSkyBlue"></ChartTitle>
<Background Color="SeaGreen" />
<Border Color="blue" />
<Legend Position="Right"></Legend>
<XAxisFont StringFormat="Center,Near,Character,LineLimit" Font="Tahoma, 6pt, style=Bold" ForeColor="115, 138, 156"></XAxisFont>
<YAxisFont StringFormat="Far,Near,Character,LineLimit" Font="Tahoma, 8pt, style=Bold" ForeColor="115, 138, 156"></YAxisFont>
<XTitle Text="需求名称" StringFormat="Center,Near,Character,LineLimit" Font="Tahoma, 8pt, style=Bold" ForeColor="red"></XTitle>
<YTitle Text="进度记录" StringFormat="Center,Near,Character,DirectionVertical" Font="Tahoma, 8pt, style=Bold" ForeColor="blue"></YTitle>
</Web:ChartControl>
后台的代码可以自己写:
ChartControl1.Visible = true;
ChartControl1.HasChartLegend = false;
LineChart lc = new LineChart();
lc.Line.Color = Color.Red;
lc.ShowLegend = false;
ChartPointCollection lcdata = lc.Data;
lc.Legend = "需求进度记录";
lc.DataLabels.Visible = true;
string username = DropDownListUsers.SelectedItem.Text;
string reqname = DropDownListUserReqs.SelectedItem.Text;
ChartText ct = new ChartText();
ct.Text = reqname;
ChartControl1.XTitle = ct;
string userid = GetUseridByUserName(username).ToString();
string getReqsbyuseridsql = " select a.Req_Id from [RequirementsStatus] a left join Reqirements b on a.Req_Id=b.Req_Id where a.Req_User_id='" + userid + "'";
string reqid = GetReqidbyReqname(reqname);
string title = DropDownListUserReqs.SelectedItem.Text + "_需要要求完成时间:" + DBHelper.ExecuteScalar("select Req_Workload from Reqirements where Req_Id='"+reqid+"'").ToString();
ChartControl1.ChartTitle.Text = title;
string reqprosql = "select a.Req_Progress,a.Req_UpdateTime from RequirementsProgressRecord a where a.Req_Id='" + reqid + "' order by a.Req_UpdateTime asc";
DataTable reqpro = DBHelper.GetDataTable(reqprosql);
foreach (DataRow reqrow in reqpro.Rows)
{
string pro = reqrow.ItemArray[0].ToString();
string rowdate = reqrow.ItemArray[1].ToString();
DateTime time = DateTime.Parse(rowdate);
string day = time.Month.ToString() + "月" + time.Day.ToString() + "日";
string strsigntime = time.Hour.ToString() + "." + time.Minute.ToString();
float signtime = float.Parse(strsigntime);
float rqp = float.Parse(pro);
lcdata.Add(new ChartPoint(day, rqp));
}
ChartControl1.Charts.Add(lc);
ChartControl1.BottomChartPadding = 30;
ChartControl1.XAxisFont.Font = new Font("Tahoma", 9);
ChartControl1.RedrawChart();