如何使用Vb.Net绘制图表中一个月内的天数 [英] How Do I Plot The Count Of Days In A Month In Chart Using Vb.Net

查看:68
本文介绍了如何使用Vb.Net绘制图表中一个月内的天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,它将从SQL-Server加载到DataGridView中,它将包含像Days,Month和Year这样的列。我想在X轴上绘制年份和月份,在Y轴上绘制日计数。是.Net的新手。是否有任何方法可以做到这一点?

I have a Table which will be loaded in a DataGridView From SQL-Server and it will have columns Like Days, Month , and Year. I want to plot Year and Month in X axis and The Day Count in Y axis. Am new to .Net .Is there any way to do this ??

推荐答案

在表单上删除Chart控件,并将DataBind与DataGridView放在同一个源上。

将Series.XValueMember设置为您想要沿着X轴的类的属性名称,将Series.YValueMembers设置为Y轴属性。



如果你需要从两列作为一个轴值绘制,那么这很痛苦 - 通常表明你的数据源设计得很糟糕:你应该使用DateTime值而不是单独的Year,Month,和day值因为它很远,很容易得到分隔的无效日期。

但是......只需创建一个包含DateTime和Count属性的新类,并创建它们的List,每个实例持有从Year和Month创建的DateTime,并将Day设置为第一个。使用该列表作为图表的数据源,并相应地设置x和y成员。
Drop a Chart control on your form, and DataBind it to the same source as the DataGridView.
Set the Series.XValueMember to the name of the property in your class you want along the X axis, and the Series.YValueMembers to the Y axis property.

If you need to plot from two columns as one axis value then that's a pain - and normally indicates that your data source is badly designed: you should be using a DateTime value instead of holding separate Year, Month, and Day values as it's far, far to easy to get invalid dates with separates.
But...just create a new class that holds a DateTime and a Count properties, and create a List of them, which each instance holding a DateTime created from Year and Month, with the Day set to the first. Use that list as the datasource for the Chart, and set the x and y members appropriately.


这篇关于如何使用Vb.Net绘制图表中一个月内的天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆