/// <summary>
/// 定义Series适用大部分图形样式------不适合样式有、饼图、空心饼图等
/// </summary>
/// <param name="name"></param>
/// <param name="stype"></param>
/// <param name="XValueMember"></param>
/// <param name="YValueMembers"></param>
/// <returns></returns>
public static Series SetSeriesStyle(string name, SeriesChartType stype, string XValueMember, string YValueMembers)
{
Series series = new Series(name);
string PointWidth = "0.8";
series.XValueMember = XValueMember;
series.YValueMembers = name;
series.ToolTip = "#VAL";
series["DrawingStyle"] = "Cylinder";
// series.MarkerStyle = MarkerStyle.Circle;点标记
series["PointWidth"] = PointWidth;
series.ChartType = stype;
//series.ChartArea = name;
//series.Legend = name;
return series;
}
series["PointWidth"] = PointWidth; 绘制的宽度
series.XValueMember = XValueMember; 绑定数据的X轴显示数据的 对应列名
series.YValueMembers = name; 绑定数据的Y轴显示数据的 对应列名
series["DrawingStyle"] = "Cylinder"; 绘制图形的 样式
series.ToolTip = "#VAL"; 鼠标移到上去的显示 的Y轴 对应的数据
series.ChartType = stype; 显示图形的样式 此类型为枚举类型 下面 有我翻译的一点东东 很多不准 俺是英盲
this.DropDownList1.Items.Add(new ListItem("区域填充", "13"));
this.DropDownList1.Items.Add(new ListItem("条形", "7"));
this.DropDownList1.Items.Add(new ListItem("盒型图", "28"));
this.DropDownList1.Items.Add(new ListItem("气泡", "2"));
this.DropDownList1.Items.Add(new ListItem("烛台", "20"));
this.DropDownList1.Items.Add(new ListItem("竖形", "10"));
this.DropDownList1.Items.Add(new ListItem("空心圆", "18"));
this.DropDownList1.Items.Add(new ListItem("误差条形图", "27"));
this.DropDownList1.Items.Add(new ListItem("FastLine", "6"));
this.DropDownList1.Items.Add(new ListItem("FastPoint", "1"));
this.DropDownList1.Items.Add(new ListItem("漏斗形", "33"));
this.DropDownList1.Items.Add(new ListItem("钩形图", "31"));
this.DropDownList1.Items.Add(new ListItem("线形", "3"));
this.DropDownList1.Items.Add(new ListItem("饼图", "17"));
this.DropDownList1.Items.Add(new ListItem("点形", "0"));
this.DropDownList1.Items.Add(new ListItem("点和图", "32"));
this.DropDownList1.Items.Add(new ListItem("极地图表", "26"));
this.DropDownList1.Items.Add(new ListItem("金字塔形", "34"));
this.DropDownList1.Items.Add(new ListItem("雷达形", "25"));
this.DropDownList1.Items.Add(new ListItem("变化幅度", "21"));
this.DropDownList1.Items.Add(new ListItem("横着", "23"));
this.DropDownList1.Items.Add(new ListItem("竖着条形", "24"));
this.DropDownList1.Items.Add(new ListItem("Renko", "29"));
this.DropDownList1.Items.Add(new ListItem("曲线", "4"));
this.DropDownList1.Items.Add(new ListItem("曲线区域填充", "14"));
this.DropDownList1.Items.Add(new ListItem("曲线区域填充1", "22"));
this.DropDownList1.Items.Add(new ListItem("累加折线区域填充", "15"));
this.DropDownList1.Items.Add(new ListItem("累加折线区域填充百分比", "16"));
this.DropDownList1.Items.Add(new ListItem("累加条形", "8"));
this.DropDownList1.Items.Add(new ListItem("累加条形百分比", "9"));
this.DropDownList1.Items.Add(new ListItem("累加列", "11"));
this.DropDownList1.Items.Add(new ListItem("累加列百分比", "12"));
this.DropDownList1.Items.Add(new ListItem("T行线", "5"));
this.DropDownList1.Items.Add(new ListItem("股票图形", "19"));
this.DropDownList1.Items.Add(new ListItem("ThreeLineBreak", "30"));
下面是微软的枚举,简单的说下 new ListItem("累加列", "11") 后面的11 对应的就是 StackedColumn = 11,
// 摘要:
// Specifies a chart type for a System.Web.UI.DataVisualization.Charting.Series.
public enum SeriesChartType
{
// 摘要:
// Point chart type.
Point = 0,
//
// 摘要:
// FastPoint chart type.
FastPoint = 1,
//
// 摘要:
// Bubble chart type.
Bubble = 2,
//
// 摘要:
// Line chart type.
Line = 3,
//
// 摘要:
// Spline chart type.
Spline = 4,
//
// 摘要:
// StepLine chart type.
StepLine = 5,
//
// 摘要:
// FastLine chart type.
FastLine = 6,
//
// 摘要:
// Bar chart type.
Bar = 7,
//
// 摘要:
// Stacked bar chart type.
StackedBar = 8,
//
// 摘要:
// Hundred-percent stacked bar chart type.
StackedBar100 = 9,
//
// 摘要:
// Column chart type.
Column = 10,
//
// 摘要:
// Stacked column chart type.
StackedColumn = 11,
//
// 摘要:
// Hundred-percent stacked column chart type.
StackedColumn100 = 12,
//
// 摘要:
// Area chart type.
Area = 13,
//
// 摘要:
// Spline area chart type.
SplineArea = 14,
//
// 摘要:
// Stacked area chart type.
StackedArea = 15,
//
// 摘要:
// Hundred-percent stacked area chart type.
StackedArea100 = 16,
//
// 摘要:
// Pie chart type.
Pie = 17,
//
// 摘要:
// Doughnut chart type.
Doughnut = 18,
//
// 摘要:
// Stock chart type.
Stock = 19,
//
// 摘要:
// Candlestick chart type.
Candlestick = 20,
//
// 摘要:
// Range chart type.
Range = 21,
//
// 摘要:
// Spline range chart type.
SplineRange = 22,
//
// 摘要:
// RangeBar chart type.
RangeBar = 23,
//
// 摘要:
// Range column chart type.
RangeColumn = 24,
//
// 摘要:
// Radar chart type.
Radar = 25,
//
// 摘要:
// Polar chart type.
Polar = 26,
//
// 摘要:
// Error bar chart type.
ErrorBar = 27,
//
// 摘要:
// Box plot chart type.
BoxPlot = 28,
//
// 摘要:
// Renko chart type.
Renko = 29,
//
// 摘要:
// ThreeLineBreak chart type.
ThreeLineBreak = 30,
//
// 摘要:
// Kagi chart type.
Kagi = 31,
//
// 摘要:
// PointAndFigure chart type.
PointAndFigure = 32,
//
// 摘要:
// Funnel chart type.
Funnel = 33,
//
// 摘要:
// Pyramid chart type.
Pyramid = 34,
}
重点介绍的是饼图 饼图 有些特殊
/// <summary>
/// 适合样式有 、饼图、空心饼图
/// </summary>
/// <param name="name"></param>
/// <param name="stype"></param>
/// <param name="xValues"></param>
/// <param name="yValues"></param>
/// <returns></returns>
public static Series SetSeriesStyle(string name, SeriesChartType stype, string[] xValues, double[] yValues)
{
Series series = new Series(name);
series.ChartType = stype;
// series["PointWidth"] = PointWidth;
series.Points.DataBindXY(xValues, yValues);
for (int i = 0; i < yValues.Count(); i++)
{
series.Points[i].LegendText = xValues[i] + " #VAL";
//series.Points[i].Label = xValues[i] + " #PERCENT{P1}";
//series.Points[i].Label = "#PERCENT{P1}";
}
series.ToolTip = "#VALX #PERCENT{P1}";
series["PieLabelStyle"] = "Disabled";
series.ChartArea = name;
series.Legend = name;
return series;
}
在这里详细介绍下
series.ToolTip = "#VALX #PERCENT{P1}"; 这个 #VALX 是用来获取 饼图的实际数字的 #PERCENT{P1}是用来获取百分比的
我在在网上查饼图资料是 居然有人 用自己来计算这个 虽然我不知道微软这个如何 来计算的 但是他饼图都能画出来 百分比它还算不 出来吗 建议大家在学习这个控件的时候多看微软示例 微软的已经很全了