dotcharting画图控件的扩展内容非常广,这里主要介绍一些图形样式的扩展内容说明框的位置,xy轴样式,主题栏样式,ann,ax两种非常规说明框的使用
代码如下:
Code
if(ListBox2.Items.Count==0)
{
return;
}
Chart1.Visible = true;
float maxstroke = 0;
float maxtimes = 0;
float maxwork = 0;
float minwork = 0;
if (ListBox2.Items.Count != 0)
{
SeriesCollection SC = new SeriesCollection();
//定义说明框格式,只显示线型和名字
Chart1.LegendBox.Template = "%Icon%Name";
Chart1.LegendBox.DefaultEntry.Value = "";
Chart1.Debug = false;
//Chart1.Type = ChartType.Scatter;
//线条形状为直线
Chart1.DefaultSeries.Type = SeriesType.Line;
//装载画完图的图形的文件夹的名字,此处为相对路径,也可以用绝对路径
Chart1.TempDirectory = "tempdata";
//图形高度
Chart1.Height = 450;
//图形宽度
Chart1.Width = 650;
//标题栏的位置为满宽度
Chart1.TitleBox.Position = TitleBoxPosition.Full;
//标题框中文字的对齐方式
Chart1.TitleBox.Label.Alignment = StringAlignment.Center;
//画图区域的背景颜色,也可以用256位像素来定义
Chart1.ChartArea.Background = new Background(Color.Ivory);
//是否显示曲线中的数据点
Chart1.DefaultSeries.DefaultElement.Marker.Type = ElementMarkerType.None;
//Chart1.ChartArea.ClearColors();
//Chart1.LegendBox.Orientation = dotnetCHARTING.Orientation.Bottom;
//自定义说明框的字体以及颜色
Chart1.LegendBox.LabelStyle = new dotnetCHARTING.Label("", new Font("宋体", 9), Color.Black);
//定义说明框的形状
Chart1.LegendBox.CornerTopLeft = BoxCorner.Square;
Chart1.LegendBox.CornerBottomRight = BoxCorner.Square;
//定义说明框的背景颜色
Chart1.LegendBox.Background = new Background(System.Drawing.Color.Ivory);
Chart1.TitleBox.Background = new Background(System.Drawing.Color.Ivory);
//X,Y轴尾部的形状,箭头还是其他形状
Chart1.DefaultAxis.Line.EndCap = LineCap.ArrowAnchor;
//X,y轴线条宽度
Chart1.DefaultAxis.Line.Width = 2;
Chart1.ShadingEffectMode = ShadingEffectMode.Two;
Chart1.TitleBox.CornerBottomLeft = BoxCorner.Square;
Chart1.TitleBox.CornerBottomRight = BoxCorner.Square;
Chart1.TitleBox.CornerTopLeft = BoxCorner.Round;
Chart1.TitleBox.CornerTopRight = BoxCorner.Round;
Chart1.TitleBox.Label = new dotnetCHARTING.Label(DDL_JingHao.SelectedValue.Trim().ToString() + "地面示功图比较", new Font("宋体", 9), Color.Black);
Chart1.XAxis.Label.Text = "位移(m)";
Chart1.YAxis.Label.Text = "载荷(kN)";
//定义多条曲线的颜色集合
Color[] serColor = new Color[] { Color.FromArgb(255,0,0), Color.FromArgb(0,0,255), Color.FromArgb(53,202,53), Color.FromArgb(142,67,188), Color.FromArgb(0,0,0)
, Color.FromArgb(3,199,209), Color.FromArgb(222,22,233), Color.FromArgb(234,117,0),
Color.FromArgb(128,64,64), Color.FromArgb(205,199,199), Color.FromArgb(151,151,0) };//设置每条曲线的颜色
ArrayList maxWorkList = new ArrayList();//存储每条曲线的最大载荷
ArrayList minWorkList = new ArrayList();//存储每条曲线的最小载荷
for (int i = 0; i < ListBox2.Items.Count; i++)
{
string t_Sql;
switch (rbtnChartType.SelectedValue.Trim())
{
case "地面功图":
t_Sql = "select wl_time,wl_distance,wl_times,wl_maxwork,wl_minwork,wl_move,wl_work from well_data where wellbzid='" + DDL_JingHao.SelectedValue.Trim() + "' and wl_time=convert(datetime,'" + ListBox2.Items[i].Text.Trim() + "',120)";
break;
case "泵功图":
t_Sql = "select well_time as wl_time,wl_distance,wl_times,bwmax as wl_maxwork,bwmin as wl_minwork,wl_move,wl_work from well_btdata where wellbzid='" + DDL_JingHao.SelectedValue.Trim() + "' and well_time=convert(datetime,'" + ListBox2.Items[i].Text.Trim() + "',120)";
break;
default:
t_Sql = "select wl_time,wl_distance,wl_times,wl_maxwork,wl_minwork,wl_move,wl_work from well_data";
break;
}
DataSet DS = DataHandle.ExecuteSQL(t_Sql);
Series s = new Series();
if (DS.Tables[0].Rows.Count != 0)
{
try
{
maxstroke = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_distance"]);
maxtimes = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_times"]);
minwork = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_minwork"]);
maxwork = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_maxwork"]);
maxWorkList.Add(maxwork);
minWorkList.Add(minwork);
string movepack = DS.Tables[0].Rows[0]["wl_move"].ToString();
string workpack = DS.Tables[0].Rows[0]["wl_work"].ToString();
string[] onemovepack = System.Text.RegularExpressions.Regex.Split(movepack, @"[;]+");
string[] oneworkpack = System.Text.RegularExpressions.Regex.Split(workpack, @"[;]+");
if (onemovepack[onemovepack.Length - 1] != null && onemovepack[onemovepack.Length - 1].ToString().Trim() == "")
{
onemovepack[onemovepack.Length - 1] = onemovepack[0].Trim();
}
if (oneworkpack[oneworkpack.Length - 1] != null && oneworkpack[oneworkpack.Length - 1].ToString().Trim() == "")
{
oneworkpack[oneworkpack.Length - 1] = oneworkpack[0].Trim();
}
s.Name = DS.Tables[0].Rows[0]["wl_time"].ToString();
if (i < 12)
{
s.DefaultElement.Color = serColor[i];
}
else
{
Random r = new Random();
s.DefaultElement.Color = Color.FromArgb(r.Next(0, 160), r.Next(0, 160), r.Next(0, 160));
}
for (int j = 0; j < onemovepack.Length ; j++)
{
Element e1 = new Element();
e1.XValue = double.Parse(onemovepack[j].Trim());
e1.YValue = double.Parse(oneworkpack[j].Trim());
s.Elements.Add(e1);
}
SC.Add(s);
}
catch
{
}
}
else
{
Chart1.Visible = false;
return;
}
}
#region 最大最小值显示
maxWorkList.Sort();
minWorkList.Sort();
//Axismarker,非常规曲线展示,例如图形中的说明框,图形关键区域绘画等等。可以灵活运用于各种图形完善内容
if (ckbShowMax.Checked)
{
double maxValue = 0.0;
if (maxWorkList.Count != 0)
{
maxValue = Convert.ToSingle(maxWorkList[maxWorkList.Count - 1]);
}
AxisMarker Am1 = new AxisMarker("最大载荷线(" + maxValue.ToString("F") + "kN)", new Line(Color.Green), maxValue);
Am1.Line.DashStyle = DashStyle.Dash;
Chart1.YAxis.Markers.Add(Am1);
Am1.LegendEntry.Visible = false;
}
if (ckbShowMin.Checked)
{
double minValue = 0.0;
if (minWorkList.Count != 0)
{
minValue = Convert.ToSingle(minWorkList[0]);
}
AxisMarker Am2 = new AxisMarker("最小载荷线(" + minValue.ToString("F") + "kN)", new Line(Color.Green), minValue);
Am2.Line.DashStyle = DashStyle.Dash;
Chart1.YAxis.Markers.Add(Am2);
Am2.LegendEntry.Visible = false;
}
#endregion
//chart1的曲线集合加载SC
Chart1.SeriesCollection.Add(SC);
//annotation类似于axismarker
Annotation ann = new Annotation("最大冲程:" + maxstroke.ToString().Trim() + "m" + " 最大冲次:" + maxtimes.ToString().Trim() + "/min");
//定义annotation的位置
ann.Position = new Point(60, 40);
ann.DynamicSize = false;
ann.Size = new Size(220, 25);
ann.Label.Color = Color.Black;
ann.Label.Alignment = StringAlignment.Near;
ann.CornerBottomLeft = BoxCorner.Square;
ann.CornerBottomRight = BoxCorner.Square;
ann.CornerTopLeft = BoxCorner.Square;
ann.CornerTopRight = BoxCorner.Square;
ann.Background = new Background(Color.FromArgb(182,239,236));
ann.Label.Font = new Font("Arial", 12.0f, FontStyle.Regular, GraphicsUnit.Pixel);
Chart1.Annotations.Add(ann);
}
else
{
return;
}
if(ListBox2.Items.Count==0)
{
return;
}
Chart1.Visible = true;
float maxstroke = 0;
float maxtimes = 0;
float maxwork = 0;
float minwork = 0;
if (ListBox2.Items.Count != 0)
{
SeriesCollection SC = new SeriesCollection();
//定义说明框格式,只显示线型和名字
Chart1.LegendBox.Template = "%Icon%Name";
Chart1.LegendBox.DefaultEntry.Value = "";
Chart1.Debug = false;
//Chart1.Type = ChartType.Scatter;
//线条形状为直线
Chart1.DefaultSeries.Type = SeriesType.Line;
//装载画完图的图形的文件夹的名字,此处为相对路径,也可以用绝对路径
Chart1.TempDirectory = "tempdata";
//图形高度
Chart1.Height = 450;
//图形宽度
Chart1.Width = 650;
//标题栏的位置为满宽度
Chart1.TitleBox.Position = TitleBoxPosition.Full;
//标题框中文字的对齐方式
Chart1.TitleBox.Label.Alignment = StringAlignment.Center;
//画图区域的背景颜色,也可以用256位像素来定义
Chart1.ChartArea.Background = new Background(Color.Ivory);
//是否显示曲线中的数据点
Chart1.DefaultSeries.DefaultElement.Marker.Type = ElementMarkerType.None;
//Chart1.ChartArea.ClearColors();
//Chart1.LegendBox.Orientation = dotnetCHARTING.Orientation.Bottom;
//自定义说明框的字体以及颜色
Chart1.LegendBox.LabelStyle = new dotnetCHARTING.Label("", new Font("宋体", 9), Color.Black);
//定义说明框的形状
Chart1.LegendBox.CornerTopLeft = BoxCorner.Square;
Chart1.LegendBox.CornerBottomRight = BoxCorner.Square;
//定义说明框的背景颜色
Chart1.LegendBox.Background = new Background(System.Drawing.Color.Ivory);
Chart1.TitleBox.Background = new Background(System.Drawing.Color.Ivory);
//X,Y轴尾部的形状,箭头还是其他形状
Chart1.DefaultAxis.Line.EndCap = LineCap.ArrowAnchor;
//X,y轴线条宽度
Chart1.DefaultAxis.Line.Width = 2;
Chart1.ShadingEffectMode = ShadingEffectMode.Two;
Chart1.TitleBox.CornerBottomLeft = BoxCorner.Square;
Chart1.TitleBox.CornerBottomRight = BoxCorner.Square;
Chart1.TitleBox.CornerTopLeft = BoxCorner.Round;
Chart1.TitleBox.CornerTopRight = BoxCorner.Round;
Chart1.TitleBox.Label = new dotnetCHARTING.Label(DDL_JingHao.SelectedValue.Trim().ToString() + "地面示功图比较", new Font("宋体", 9), Color.Black);
Chart1.XAxis.Label.Text = "位移(m)";
Chart1.YAxis.Label.Text = "载荷(kN)";
//定义多条曲线的颜色集合
Color[] serColor = new Color[] { Color.FromArgb(255,0,0), Color.FromArgb(0,0,255), Color.FromArgb(53,202,53), Color.FromArgb(142,67,188), Color.FromArgb(0,0,0)
, Color.FromArgb(3,199,209), Color.FromArgb(222,22,233), Color.FromArgb(234,117,0),
Color.FromArgb(128,64,64), Color.FromArgb(205,199,199), Color.FromArgb(151,151,0) };//设置每条曲线的颜色
ArrayList maxWorkList = new ArrayList();//存储每条曲线的最大载荷
ArrayList minWorkList = new ArrayList();//存储每条曲线的最小载荷
for (int i = 0; i < ListBox2.Items.Count; i++)
{
string t_Sql;
switch (rbtnChartType.SelectedValue.Trim())
{
case "地面功图":
t_Sql = "select wl_time,wl_distance,wl_times,wl_maxwork,wl_minwork,wl_move,wl_work from well_data where wellbzid='" + DDL_JingHao.SelectedValue.Trim() + "' and wl_time=convert(datetime,'" + ListBox2.Items[i].Text.Trim() + "',120)";
break;
case "泵功图":
t_Sql = "select well_time as wl_time,wl_distance,wl_times,bwmax as wl_maxwork,bwmin as wl_minwork,wl_move,wl_work from well_btdata where wellbzid='" + DDL_JingHao.SelectedValue.Trim() + "' and well_time=convert(datetime,'" + ListBox2.Items[i].Text.Trim() + "',120)";
break;
default:
t_Sql = "select wl_time,wl_distance,wl_times,wl_maxwork,wl_minwork,wl_move,wl_work from well_data";
break;
}
DataSet DS = DataHandle.ExecuteSQL(t_Sql);
Series s = new Series();
if (DS.Tables[0].Rows.Count != 0)
{
try
{
maxstroke = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_distance"]);
maxtimes = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_times"]);
minwork = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_minwork"]);
maxwork = Convert.ToSingle(DS.Tables[0].Rows[0]["wl_maxwork"]);
maxWorkList.Add(maxwork);
minWorkList.Add(minwork);
string movepack = DS.Tables[0].Rows[0]["wl_move"].ToString();
string workpack = DS.Tables[0].Rows[0]["wl_work"].ToString();
string[] onemovepack = System.Text.RegularExpressions.Regex.Split(movepack, @"[;]+");
string[] oneworkpack = System.Text.RegularExpressions.Regex.Split(workpack, @"[;]+");
if (onemovepack[onemovepack.Length - 1] != null && onemovepack[onemovepack.Length - 1].ToString().Trim() == "")
{
onemovepack[onemovepack.Length - 1] = onemovepack[0].Trim();
}
if (oneworkpack[oneworkpack.Length - 1] != null && oneworkpack[oneworkpack.Length - 1].ToString().Trim() == "")
{
oneworkpack[oneworkpack.Length - 1] = oneworkpack[0].Trim();
}
s.Name = DS.Tables[0].Rows[0]["wl_time"].ToString();
if (i < 12)
{
s.DefaultElement.Color = serColor[i];
}
else
{
Random r = new Random();
s.DefaultElement.Color = Color.FromArgb(r.Next(0, 160), r.Next(0, 160), r.Next(0, 160));
}
for (int j = 0; j < onemovepack.Length ; j++)
{
Element e1 = new Element();
e1.XValue = double.Parse(onemovepack[j].Trim());
e1.YValue = double.Parse(oneworkpack[j].Trim());
s.Elements.Add(e1);
}
SC.Add(s);
}
catch
{
}
}
else
{
Chart1.Visible = false;
return;
}
}
#region 最大最小值显示
maxWorkList.Sort();
minWorkList.Sort();
//Axismarker,非常规曲线展示,例如图形中的说明框,图形关键区域绘画等等。可以灵活运用于各种图形完善内容
if (ckbShowMax.Checked)
{
double maxValue = 0.0;
if (maxWorkList.Count != 0)
{
maxValue = Convert.ToSingle(maxWorkList[maxWorkList.Count - 1]);
}
AxisMarker Am1 = new AxisMarker("最大载荷线(" + maxValue.ToString("F") + "kN)", new Line(Color.Green), maxValue);
Am1.Line.DashStyle = DashStyle.Dash;
Chart1.YAxis.Markers.Add(Am1);
Am1.LegendEntry.Visible = false;
}
if (ckbShowMin.Checked)
{
double minValue = 0.0;
if (minWorkList.Count != 0)
{
minValue = Convert.ToSingle(minWorkList[0]);
}
AxisMarker Am2 = new AxisMarker("最小载荷线(" + minValue.ToString("F") + "kN)", new Line(Color.Green), minValue);
Am2.Line.DashStyle = DashStyle.Dash;
Chart1.YAxis.Markers.Add(Am2);
Am2.LegendEntry.Visible = false;
}
#endregion
//chart1的曲线集合加载SC
Chart1.SeriesCollection.Add(SC);
//annotation类似于axismarker
Annotation ann = new Annotation("最大冲程:" + maxstroke.ToString().Trim() + "m" + " 最大冲次:" + maxtimes.ToString().Trim() + "/min");
//定义annotation的位置
ann.Position = new Point(60, 40);
ann.DynamicSize = false;
ann.Size = new Size(220, 25);
ann.Label.Color = Color.Black;
ann.Label.Alignment = StringAlignment.Near;
ann.CornerBottomLeft = BoxCorner.Square;
ann.CornerBottomRight = BoxCorner.Square;
ann.CornerTopLeft = BoxCorner.Square;
ann.CornerTopRight = BoxCorner.Square;
ann.Background = new Background(Color.FromArgb(182,239,236));
ann.Label.Font = new Font("Arial", 12.0f, FontStyle.Regular, GraphicsUnit.Pixel);
Chart1.Annotations.Add(ann);
}
else
{
return;
}
图形展示效果如下: