110,567
社区成员
发帖
与我相关
我的任务
分享
ZedGraph.PointPairList list = new ZedGraph.PointPairList();
ZedGraph.LineItem myCurve;
ZedGraph.PointPairList list2 = new ZedGraph.PointPairList();
ZedGraph.LineItem myCurve2;
float splitX = (float)Long/ 10;
for (float x = 0; x < Long; x=x+splitX)
{
float y = (float)PowerLine.yr(x, du, Zhong, Long, Fln);//函数关系
list.Add(x, y);
}
myCurve = zedGraphControl1.GraphPane.AddCurve("My Curve",list, Color.DarkGreen, ZedGraph.SymbolType.None);
for (float x = (float)Long; x <Long+ 200; x++)
{
float y = (float)PowerLine.yr(x, du, Zhong, Long+ 200, Fln);
list2.Add(x, y);
}
myCurve2 = zedGraphControl1.GraphPane.AddCurve("test", list2, Color.Red, ZedGraph.SymbolType.None);
zedGraphControl1.AxisChange();
zedGraphControl1.Refresh();
//动态创建视图
string startTemp = start + "-01 00:00:00";
string endTemp;
if (Convert.ToInt32(cmendmonth.Text) < 12)
{
endTemp = cmendyear.Text + "-" + Convert.ToString(Convert.ToInt32(cmendmonth.Text) + 1) + "-01 00:00:00";
}
else
{
endTemp = Convert.ToString(Convert.ToInt32(cmendyear.Text) + 1) + "-" + "01-01 00:00:00";
}
operation.CreateViwPro(startTemp, endTemp);
string strWhere = "";
if (ltvDeptInfo.CheckedItems.Count > 0)
{
strWhere = " Where ";
}
string[] names = new string[ltvDeptInfo.CheckedItems.Count];
string[] deptId = new string[ltvDeptInfo.CheckedItems.Count];
for (int i = 0; i < ltvDeptInfo.CheckedItems.Count; i++)
{
strWhere += " c.deptid = '" + ltvDeptInfo.CheckedItems[i].Tag.ToString() + "'";
if (i < ltvDeptInfo.CheckedItems.Count - 1)
{
strWhere += " or";
}
deptId[i] = ltvDeptInfo.CheckedItems[i].Tag.ToString();
names[i] = ltvDeptInfo.CheckedItems[i].Text.ToString();
}
DataTable dt = operation.getTimecount(start, end);
string[] dateid = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
dateid[i] = dt.Rows[i]["day_id"].ToString();
}
#region 画图
this.zedGraphControl1.GraphPane.Title.Text = "";
this.zedGraphControl1.GraphPane.XAxis.Title.Text = "月份";
this.zedGraphControl1.GraphPane.YAxis.Title.Text = "数量";
this.zedGraphControl1.GraphPane.CurveList.Clear();
this.zedGraphControl1.GraphPane.GraphObjList.Clear();
this.zedGraphControl1.GraphPane.Fill = new Fill(Color.White, Color.LightSkyBlue, 45.0f);
this.zedGraphControl1.GraphPane.Chart.Fill = new Fill(Color.White, Color.LightSeaGreen, 45.0f);
this.zedGraphControl1.GraphPane.YAxis.Scale.Min = 0;
for (int i = 0; i < deptId.Length; i++)
{
DataTable dtvalue = operation.getqushiByDate(deptId[i], start, end);
double[] titles = new double[dtvalue.Rows.Count];
for (int j = 0; j < dtvalue.Rows.Count; j++)
{
titles[j] = double.Parse(dtvalue.Rows[j]["doccount"].ToString() == "" ? "0" : dtvalue.Rows[j]["doccount"].ToString());
}
SetStatisticalTable(dtvalue, i, names[i]);
LineItem myCurve = this.zedGraphControl1.GraphPane.AddCurve(names[i], titles, titles, GetColor());
myCurve.Tag = names[i];
}
zedGraphControl1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler);
this.zedGraphControl1.GraphPane.XAxis.Scale.TextLabels = dateid;
this.zedGraphControl1.GraphPane.XAxis.Scale.FontSpec.Size = 8;
this.zedGraphControl1.GraphPane.XAxis.Type = AxisType.Text;
this.zedGraphControl1.GraphPane.BarSettings.Type = BarType.Overlay;
this.zedGraphControl1.GraphPane.YAxis.Scale.MajorStep = 5;
this.zedGraphControl1.GraphPane.XAxis.MajorTic.IsBetweenLabels = true;
this.zedGraphControl1.AxisChange();
this.zedGraphControl1.Refresh();
#endregion
/// <summary>
/// 随机成一个颜色
/// </summary>
/// <returns></returns>
public Color GetColor()
{
Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
// 对于C#的随机数,没什么好说的
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
Random RandomNum_Sencond = new Random((int)DateTime.Now.Ticks);
// 为了在白色背景上显示,尽量生成深色
int int_Red = RandomNum_First.Next(256);
int int_Green = RandomNum_Sencond.Next(256);
int int_Blue = (int_Red + int_Green > 400) ? 0 : 400 - int_Red - int_Green;
int_Blue = (int_Blue > 255) ? 255 : int_Blue;
return Color.FromArgb(int_Red, int_Green, int_Blue);
}
/// <summary>
/// 表格显示统计信息
/// </summary>
/// <param name="dt"></param>
private void SetStatisticalTable(DataTable dt, int num, string name)
{
DataTable dt2 = dgvStatistical.DataSource as DataTable;
if (num == 0 || num.Equals(0))
{
dt2 = new DataTable();
dt2.Columns.Add("deptId", typeof(String));
dt2.Columns.Add("time", typeof(String));
dt2.Columns.Add("num", typeof(String));
}
int count = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
if (dt.Rows[i]["doccount"].ToString() != "")
{
count += int.Parse(dt.Rows[i]["doccount"].ToString());
}
}
string endtime = start;
string starttime = end;
//当时间相同的时候 只显示一次
string time = "";
if (endtime.Equals(starttime))
{
time = starttime;
}
else
{
time = endtime + " 至 " + starttime;
}
DataRow dr = dt2.NewRow();
dr["deptId"] = name;
dr["time"] = time;
dr["num"] = count.ToString();
dt2.Rows.Add(dr);
dgvStatistical.DataSource = dt2;
}