快捷搜索:  as  2018  FtCWSyGV  С˵  test  xxx  Ψһ  w3viyKQx

下载澳门新葡亰官网App:MSChart使用经验总结



在用到图表展示某项、多项信息的统计环境,很正常遐想到MSChart控件。

以VS2008开拓为例,在对象箱也中右击,选择”choose items“,打开对话框,选择COM组件Tab页,勾选上Microsoft Chart Control,version 6.0(OLEDB),然后在窗体中拖入此控件即可(默认名称为Chart1)。

关键的难点有对MSChart赋值,X、Y轴划分刻度以及临盆图例。下面结合开拓实例,稍作总结下:

标题设置:this.Chart1.Title.Text = "tableName";

图例设置:for (int c = 1; c 注:图例的下标从1开始

图表类型的选择:this.Chart1.chartType = VtChChartType.VtChChartType2dBar;(VtChChartType2dPie/VtChChartType2dLine)

图表内容绑定:this.Chart1.ChartData = arrResult;(一维数组、二维数组)

X、Y轴显示值间距:

Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1.0; //X轴数据显示距离

Chart1.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Days;

Chart1.ChartAreas["ChartArea1"].AxisX.Interva下载澳门新葡亰官网ApplOffset = 0.0;

Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffsetType = DateTimeIntervalType.Days;

Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M-d";

Chart1.ChartAreas["ChartArea1"].AxisY.Interval = 200;//y轴数据显示距离

贴一张统计的效果图:

案例代码。1 四象限图

chartareas>

asp:chartarea Name="ChartArea1" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" BackSecondaryColor="White" BackColor="Gainsboro" ShadowColor="Transparent" BackGradientStyle="TopBottom">area3dstyle Rotation="10" 扭转角度 perspective="10" Inclination="15" IsRightAngleAxes="False" wallwidth="0" IsClustered="False" >area3dstyle>

axisy linecolor="64, 64, 64, 64" IsLabelAutoFit="False" IsStartedFromZero="false" Crossing="8" y轴原点位置>labelstyle font="Trebuchet MS, 8.25pt, style=Bold"/>

majorgrid linecolor="64, 64, 64, 64" Enabled="false" />axisy>

axisx linecolor="64, 64, 64, 64" IsLabelAutoFit="False" IsStartedFromZero="false" 是否从0点开始 Interval="auto"Minimum="70"X轴最小显示Crossing="90"X轴原点位置 >labelstyle font="Trebuchet MS, 8.25pt, style=Bold"/>

majorgrid linecolor="64, 64, 64, 64"Enabled="false" 是否启用网格/>axisx>

asp:chartarea> chartareas>

设置最大年夜值和最小值不合颜色演示

// Find point with maximum 下载澳门新葡亰官网AppY value and change color

if (Chart_TJ.Series[0].Points.Count > 2){

DataPoint maxValuePoint = Chart_TJ.Series[0].Points.FindMaxByValue();maxValuePoin下载澳门新葡亰官网Appt.Color = Color.Red;

// Find point with minimum Y value and change color

DataPoint minValuePoint = Chart_TJ.Series[0].Points.FindMinByValue();minValuePoint.Color = Color.Orange;

}

private void Page_Lo下载澳门新葡亰官网Appad(object sender, System.EventArgs e)

{// Resolve the address to the Access database

string fileNameString = this.MapPath(".");fileNameString += "..\\..\\..\\data\\chartdata.mdb";

// Initialize a connection string

string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

// Define the database querystring mySelectQuery="SELECT * FROM REPSALES;";

// Create a database connection object using the connection string

OleDbConnection myConnection = new OleDbConnection(myConnectionString);

// Create a database command on the connection using queryOleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

// Open the connection

myCommand.Connection.Open();

// Create a database readerOleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Data bind chart to a table where all rows are grouped in series by the "Name" column

Chart1.DataBindCrossTable(myReader,

"Name","Year",

"Sales","Label=Commissions{C}");

// Close the reader and the connection

myReader.Close();myConnection.Close();

}

// Set series appearance

MarkerStyle marker = MarkerStyle.Star4;这里要留意。线条跨越9 的话,最多9个Star。marker.Star 要null下。foreach(Series ser in Chart1.Series)

{ser.ShadowOffset = 2;

ser.BorderWidth = 3;ser.ChartType = SeriesChartType.Line;

ser.MarkerSiz下载澳门新葡亰官网Appe = 12;ser.MarkerStyle = marker;

ser.MarkerBorderColor = Color.FromArgb(64, 64, 64);ser.Font = new Font("Trebuchet MS", 8, FontStyle.Bold);

marker++;}

常用事故:

数据绑定要领1

Chart1.Series[0].Points.AddXY(zhiBiaoDt.Rows[i]["TargetName"].ToString(), zhiBiaoDt.Rows[i]["BenDanweiScore"].ToString());

Chart1.Series[0].Points[i - 1].ToolTip = zhiBiaoDt.Rows[i]["BenDanweiScore"].ToString();

Chart1.Series[1].Points.AddXY(zhiBiaoDt.Rows[i]["TargetName"].ToString(), zhiBiaoDt.Rows[i]["QiTaDanweiScore"].ToString());Chart1.Series[1].Points[i - 1].ToolTip = zhiBiaoDt.Rows[i]["QiTaDanweiScore"].ToString();

//绑定统计报表添加属性

Chart_TJ.Series[0].Name = company;Chart_TJ.Series[0].ChartType = SeriesChartType.Radar;

Chart_TJ.Series[0].IsValueShownAsLabel = false;//Chart_TJ.Series[0].IsVisibleInLegend = false;

Legend leg = new Legend(); 添加图例leg.BackColor = Chart_TJ.Series[0].Color;

leg.Name = company;Chart_TJ.Legends.Add(leg);

Chart1.Series[0]["DrawingStyle"] = "Cylinder";圆柱(圆柱体)风格

Chart1.Series[1]["DrawingStyle"] = "Cylinder";

Chart2.Series[0]["LabelStyle"] ="Bottom"; 数据标签位置有left righttoplefp bottomleftbottomrigth ……

Chart2.Series[1]["LabelStyle"] = "Bottom";

Series1.Points.DataBind()

绑定命据点聚拢,假如要在一个MSChart控件的一个绘图区(ChartArea)内添加多个不合数据源的图表,就用这个主动绑定命据聚拢的措施。可以将表中指定字段的值绑定到指定的坐标轴上。

MSChart1.DataBind()

给全部MSChart绑定一个数据源,该MSChart中的图表整个可以应用该数据源作为统计滥觞。

留意。给图绑定命据时刻,数据类型只管即便统一。不要一个是x字符型 Y decimal。

您可能还会对下面的文章感兴趣: