用于在Reportviewer和图表中显示sql数据的c#win表单脚本

用于在Reportviewer和图表中显示sql数据的c#win表单脚本,c#,sql,C#,Sql,我在SQL2012中有一个带有字段名id、时间和计数器的表。它是由一个应用程序自动生成的,该应用程序不断记录计数器的值,并且该值每时每刻都在增加。时间字段是datetime。我想用c#winforms以两种格式显示此表,第一种是可以显示实时最近值计数器值的图表,最后一天的步长为1小时,最后一个月和过去几年,它类似于股票图表。这里的诀窍是计数器值每时每刻都在增加。 还需要在reportviewer中显示相同的数据 请在visual studio 2012中为我提供解决方案。 谢谢我提供的链接包含了

我在SQL2012中有一个带有字段名id、时间和计数器的表。它是由一个应用程序自动生成的,该应用程序不断记录计数器的值,并且该值每时每刻都在增加。时间字段是datetime。我想用c#winforms以两种格式显示此表,第一种是可以显示实时最近值计数器值的图表,最后一天的步长为1小时,最后一个月和过去几年,它类似于股票图表。这里的诀窍是计数器值每时每刻都在增加。 还需要在reportviewer中显示相同的数据

请在visual studio 2012中为我提供解决方案。
谢谢

我提供的链接包含了大量示例,您可以使用这些示例来处理此问题。我以前只使用MSCharts创建这些图表的静态图像以在报告中打印它们,但我可以提供帮助

我想您已经将MSChart组件添加到表单中,并指定了要使用的表类型(饼图、折线图等)

您需要做的第一件事是将需要的数据绑定到表中。此代码取自我提供给您的示例链接:

  // Access database
System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm mainForm = (System.Windows.Forms.DataVisualization.Charting.Utilities.SampleMain.MainForm)this.ParentForm;
string fileNameString = mainForm.applicationPath + "\\data\\chartdata.mdb";

// Initialize a connection string    
string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

// Define the database query    
string mySelectQuery="SELECT * FROM YOURTABLE;";

// Create a database connection object using the connection string    
OleDbConnection myConnection = new OleDbConnection(myConnectionString);

// Create a database command on the connection using query    
OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);

// Open the connection    
myCommand.Connection.Open();

// Create a database reader    
OleDbDataReader myReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);

// Since the reader implements and IEnumerable, pass the reader directly into
// the DataBindTable method with the name of the Column to be used as the XValue
Chart1.DataBindTable(myReader, "Date");

// Close the reader and the connection
myReader.Close();
myConnection.Close();

一旦您能够按照需要的方式在MSChart中显示数据,您需要创建一个“更新”方法,该方法将在一定时间内执行,以更新表中的值。

欢迎使用StackOverflow。不幸的是,不包含任何工作代码或不显示您在解决问题方面的努力的问题是离题的。请包括您的代码,并提出更具体的问题。对不起,您是否试图在MSChart中实时显示值并在更改时更新此值?您将在何处显示此图表?在windows窗体中?请查看本网站中的示例: