2024年4月4日发(作者:)

C# chart控件绘制多图表区图像

想要根据数据库中记录个数动态决定chart控件的绘图区域,保证它们大小均匀,在网上找

了N久么有发现满意答案,纠结了快一天的时间,终于把问题解决了,贴出来供大家分享

O(∩_∩)O~

前面的代码中定义一个series对象数组:

List listSer = new List();

引发动态生成图表的按钮事件完整如下:

private void button1_Click(object sender, EventArgs e)

{

OCon Mycon = new OCon();

OracleConnection conn = ();

();

string sqlString = "select count(*) from dotrelation where dotdesc like

'2%路基%温度%'";

num = RL(conn, sqlString);//获得数据库中满足条件的记录数

//("满足条件的数据记录为" + num);

int heightPer = 100 / num;//计算每个绘图区高度

for (int i = 0; i < num; i++)

{

string serName = "test" + ng();

(new Series(serName));//对象数组

fillData(date);//初始化数组此方法自己定义的

initialSeries((Series)listSer[i], , date);

("ANOTHER" + i);

//这里是关键!!!!!

reas[i]. = 100;//绘图区域在控件中的宽

度 100是百分比

reas[i]. = heightPer;

reas[i].Position.X = 5;//绘图区域在控件中的绝对位置

横坐标

reas[i].Position.Y = 3 + heightPer * i;//绘图区域在

控件中的绝对位置纵坐标

reas[i].lor = ;

reas[i].lor = ;

reas[i].dth = 2;

reas[i].dth = 2;

reas[i]. = "监测值";

//设置网格线

reas[i].lor = ;

reas[i].al = 2;//网格间隔

reas[i].al = 2;