C#用componentertainment One的C1Chart绘制winform饼
(2009-03-19 15:18:44)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing.Drawing2D;
using System.Collections;
using C1.Win.C1Chart;
using C1.Win.C1ChartBase;
namespace WindowsApplication2
{
public
partial class Form1 : Form
{
Database db = new Database();
public Form1()
{
InitializeComponent();
}
public void GetPieData()
{
c1Chart1.Header.Text = "学生状态图";
c1Chart1.Footer.Text = "在校/在宿/实习";
c1Chart1.Legend.Visible = true;
string sql = "select count(*) from student where ZT2='在校'";
string sql2 = "select count(*) from student where ZT2='在宿'";
string sql3 = "select count(*) from student where ZT2='实习'";
float s1 = db.ExecuteScalar(sql);
float s2 = db.ExecuteScalar(sql2);
float s3 = db.ExecuteScalar(sql3);
PointF[] data = new PointF[3];
data[0] = new PointF(2,s1);
data[1] = new PointF(1, s2);
data[2] = new PointF(2, s3);
//清除现有的饼图图像(在画新饼图之前先清空现有图像)
ChartDataSeriesCollection dscoll =
c1Chart1.ChartGroups[0].ChartData.SeriesList;
dscoll.Clear();
//汇图,即将点数组交给控件,它会自己分配,并画出图形
//给区块加标签
for (int i = 0; i < data.Length; i++)
{string[] str1={"在校","在宿","实习"};
ChartDataSeries series = dscoll.AddNewSeries();
series.PointData.Length = 1;
series.Y[0] = data[i].Y;
C1.Win.C1Chart.Label lbl =
c1Chart1.ChartLabels.LabelsCollection.AddNewLabel();
lbl.Text = string.Format(str1[i] + "共"+ data[i].Y+"人");
lbl.Compass = LabelCompassEnum.Radial;
lbl.Offset = 20;
lbl.Connected = true;
lbl.Visible = true;
lbl.AttachMethod = AttachMethodEnum.DataIndex;
|