带有Microsoft图表控件的实时图表

带有Microsoft图表控件的实时图表

本文介绍了带有Microsoft图表控件的实时图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

我正在建立一个使用Microsoft Control Charts实时绘制图表的项目.图表的数据源每隔几秒钟更改一次以重新加载数据.但是我遇到了麻烦.错误为"{"跨线程操作无效:控制..."

每次检查线程完成时,我都使用线程作业来启动线程.



Hi Guys.

I am building a project that draw a chart with real time using Microsoft Control Charts. Data source of chart changes every a few seconds to reload data. but i have got a trouble with it. The error is ''{"Cross-thread operation not valid: Control...''

I use thread job to start thread every time when checking thread is complete.



private void gLoads()
  {

   jHOSEIDX = new ThreadStart(LoadChart);
   tHOSEIDX = new Thread(jHOSEIDX);
   GTimer.Interval = 10000; // 10 seconds
   GTimer.Tick += new EventHandler(Otherwise);
   GTimer.Enabled = true;
  }





这是另外一种方法.





Here is otherwise method.

private void Otherwise(object sender, EventArgs e)
{
 if (!(tHOSEIDX.ThreadState.ToString().CompareTo("Running") == 0))
 {
  jHOSEIDX = new ThreadStart(LoadChart);
  tHOSEIDX = new Thread(jHOSEIDX);
  tHOSEIDX.Start();

 }
}




Loadchart是一种重新加载数据并调整图表属性的方法.




Loadchart is a method reload data and adjust properties of chart.

private void LoadChart()
  {

    VnIndexChart.Titles[0].Text = "VN-Index";

   string fileNameString = AppDomain.CurrentDomain.BaseDirectory + @"\Data\Data.mdb";

   string myConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileNameString;

   string mySelectQuery = "SELECT TGian,Data.Ngay, Data.ChiSoHTai, Data.ChiSoGLap,Data.KLDuMua FROM Data Order By 1; ";
   OleDbConnection myConnection = new OleDbConnection(myConnectionString);
   OleDbCommand myCommand = new OleDbCommand(mySelectQuery, myConnection);
   myConnection.Open();
   VnIndexChart.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
   VnIndexChart.Series["VN-Index"].XValueMember = "TGian";
   VnIndexChart.Series["VN-Index"].YValueMembers = "ChiSoHTai";
   VnIndexChart.Series["VN-Index"].XValueType = ChartValueType.Time;

   VnIndexChart.Series["VN-IDX.ESTIMATE"].XValueMember = "TGian";
   VnIndexChart.Series["VN-IDX.ESTIMATE"].XValueType = ChartValueType.Time;
   VnIndexChart.Series["VN-IDX.ESTIMATE"].YValueMembers = "ChiSoGLap";

   VnIndexChart.Series["Qlity"].XValueMember = "TGian";
   VnIndexChart.Series["Qlity"].YAxisType = AxisType.Secondary;
   VnIndexChart.Series["Qlity"].XValueType = ChartValueType.Time;
   VnIndexChart.Series["Qlity"].YValueMembers = "KLDuMua";
   VnIndexChart.DataBind();
   UpdateChartSettings();


  }




帮我解决错误.对不起我的英语不好.

这是源代码 http://www.mediafire.com/?3yve3x0l3s8lzb8

谢谢您的时间.




Help me fix the error. Sorry for my english.

here is source code http://www.mediafire.com/?3yve3x0l3s8lzb8

Thank You for you time.

推荐答案


这篇关于带有Microsoft图表控件的实时图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:18