您的位置:首页 > 编程语言

(一)ComponentOne之WebChart(饼图)(代码示例下载)

2005-11-15 12:46 513 查看
饼图(形状如像切割后的蛋糕)
(一).配置

1.安装好ComponentOne软件.

2.建立一个WEB应用程序项目,名称为: 饼图示例

3.将ComponentOne软件自带的控件集DLL文件(不一定全部,只把需要的一部分)拷贝到自己刚建的

项目TextChart的Bin目录下面 (这里要手动放的原因是ComponentOne有时会找不到Dll)

4.双击项目里任何一个*.aspx文件,打开设计界面。 打开工具栏,在工具栏空白处右击,选“添加/删除”

项,打开自定义控件窗口,在.net frame 组件选项卡下选择ComponentOne相应的组件,如果有清楚,

就将所有的C1开头的全部勾选,点“确定按钮". 则ComponentOne的控件就显示在工具箱里面了 :)

5. 到了这一步,就可以将ComponentOne控件像一般控件一样直接拖动使用了. 拖C1WebChart控件到

窗体页面上. 然后右击控件,选 "Chart wizard..."就可以为其设置显示的样式(饼图/柱状图/折线图等)和

属性了,用法跟一般控件差不多。(除了用设计器设置外,请看下面(二)

还可以代码用代码设置)

(二) . 代码部分

1. 引用命名空间



using C1.Web.C1WebChart; //命名空间,必需加入,否则找不到里面的类和方法等
using C1.Web.C1WebChartBase;
using C1.Win.C1Chart;

protected C1.Web.C1WebChart.C1WebChart C1WebChart1; // 控件声明





2. 主要属性

C1WebChart1.Header.Text="Chart 头"; //图表头标题
C1WebChart1.Footer.Text="Chart 尾"; //图表尾文本
C1WebChart1.BackColor = Color.LightSteelBlue; //背景色
C1WebChart1.ImageFormat = System.Drawing.Imaging.ImageFormat.Png; //图像存储格式

C1WebChart1.ChartGroups.Group0.ChartType = Chart2DTypeEnum.Pie; //图表

// 类型,Chart2DTypeEnum枚举下有所有的图表样式,如饼图/柱状图等
C1WebChart1.Width=800; //图表区域宽度

3. 主要方法

a .X轴标签(坐标)的方法,直接调用即可

public void AddAxisX()
{
// label x axis with product names
Axis ax = C1WebChart1.ChartArea.AxisX;
ax.ValueLabels.Clear();
ax.AnnoMethod = AnnotationMethodEnum.ValueLabels;
for(int i = 0; i < 100; i++)
{
//DataRowView drv = dv[i];
ax.ValueLabels.Add(i, (i+1).ToString());
}
try
{
ax.Max = 10 - .5;
}
catch {}
}
b .Y轴标签(坐标)的方法,直接调用即可

public void AddAxisY()
{
// label y axis with product names
Axis ay = C1WebChart1.ChartArea.AxisY;
ay.ValueLabels.Clear();
ay.AnnoMethod = AnnotationMethodEnum.ValueLabels;
for(int i = 0; i < 10; i++)
{
//DataRowView drv = dv[i];
ay.ValueLabels.Add(i, (50*i).ToString());
}
try
{
ay.Max = 20 - .5;
}
catch {}
}

c.画饼图的核心方法
public void GetPieData()
{
C1WebChart1.Legend.Visible = true; //图表区块注释.
this.AddAxisX(); //上面方法a
this.AddAxisY(); //上面方法b

//生成数据
PointF[] data = new PointF[10];
for (int i = 0; i < data.Length; i++)
{
float y = float.Parse((3*i+5).ToString());
data[i] = new PointF(i, y);
}

//清除现有的饼图图像(在画新饼图之前先清空现有图像)
ChartDataSeriesCollection dscoll = C1WebChart2.ChartGroups[0].ChartData.SeriesList;
dscoll.Clear();

//汇图,即将点数组交给控件,它会自己分配,并画出图形
ChartDataSeries series = C1WebChart1.ChartGroups[0].ChartData.SeriesList[0];
series.PointData.CopyDataIn(data);// 这里的data是PointF类型

//给区块加标签
for(int i=0; i < data.Length; i++)
{
ChartDataSeries series = dscoll.AddNewSeries();
series.PointData.Length = 1;
series.Y[0] = data[i].Y;
series.Label="我是:"+(i+1).ToString();

//加标签
C1.Win.C1Chart.Label lbl = C1WebChart1.ChartLabels.LabelsCollection.AddNewLabel();
lbl.Text = string.Format("{0} ({1:c})","第:"+i.ToString()+"扇区", data[i].Y);
lbl.Compass = LabelCompassEnum.Radial;
lbl.Offset = 20;
lbl.Connected = true;
lbl.Visible = true;
lbl.AttachMethod = AttachMethodEnum.DataIndex;
AttachMethodData am = lbl.AttachMethodData;
am.GroupIndex = 0;
am.SeriesIndex = i;
am.PointIndex = 0;
}
}

(三).用ComponentOnet***的各种各样图示





附加一个小示例:
http://www.cnblogs.com/Files/ChengKing/C1WebChart2004.rar
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐