C # Chart about updating sensor data in real time

Source: Internet
Author: User

Because of their own graduation need to do a project on environmental monitoring, the principle is through the wireless acquisition of environmental information, the information in real-time storage to the database, the host computer is a WinForm program, the program needs to display the data collected in real-time, and the curve of the way to show it, their own toss a few days, but also some small receipts I am also just in touch with C # programming, give me feel very good.

Use the Chart control link: http://pan.baidu.com/s/1eSnYj3W Password: xqhm I use VS2010.

Analyze my purpose requirements: real-time refresh to get the database data, real-time display of data on the chart table.

My solution: 1, processing the database, searching the database data, and ready to bind the database to the table, and then, timed Refresh display chart table. Search from the Internet when said can be displayed by the data to be stored in the array or araylist, I did not, when the new data appears again, the error said that there is * * data, if always let down, the feeling will become more and more memory, will eventually die, so change the idea.

Let's take a look at my chart class.

        Private voidShowchart_from_sql (Chart MyChart,stringStr_sql,stringAxisX,stringtitle)            {myChart.Series.Clear (); Mychart.width=520;//Chart WidthMychart.height = the;//Chart HeightMychart.backcolor = color.azure;//Chart Background Color//myChart.Titles.Add ("CO2 concentration"); //Chart Title//New Connectionmychart.databindtable (Sqlhelper.getread (str_sql), AxisX); //Note that after data binding, its series is 1 instead of 0, which should be 1 post notemychart.series[0]. ChartType =Seriescharttype.spline; //mychart.chartareas["ChartArea1"]. AxisX.LabelStyle.Format = "Yyyy-mm-dd-hh:mm:ss";mychart.chartareas["ChartArea1"]. AxisX.LabelStyle.Format ="mm-dd/hh:mm";//Formatting time Stylesmychart.series[0]. Isvalueshownaslabel =false;//whether the data is displayedmychart.series[0]. Isvisibleinlegend =false;//whether to display data descriptionmychart.series[0]. MarkerStyle = markerstyle.circle;//data point marker type on linemychart.series[0]. Markersize =8;//Flag Sizemychart.chartareas[0]. Axisx.linecolor = Color.Blue;//x-Axis colormychart.chartareas[0]. Axisy.linecolor = Color.Blue;//y-Axis colormychart.chartareas[0]. Axisx.linewidth =2;//x-Axis widthmychart.chartareas[0]. Axisy.linewidth =2;//y-Axis widthmychart.chartareas[0]. Axisy.title =title; }

During the actual use I was mychart.series[1] by clearing the Series and reloading it every time. ChartType ..., when I do this, it becomes mychart.series[0] ...

What is causing the problem, every time I refresh the table, I need to call the Showchart_from_sql (Chart mychart,string str_sql,string axisx,string title) again, And each invocation is bound to produce a new series (assuming the CO2 graph), when the CO2 curve is drawn again, then the new binding mychart.databindtable (Sqlhelper.getread (str_sql), AxisX) is created again; Will get an error, because two series (CO2) conflict. In fact, I am also vague, anyway this is OK. Here's my call on this chart

             @" SELECT TOP Ten co2,addtime  From [CO2] ORDER BY addtime desc";              = time_last;              " Addtime ","CO2 concentration "

Your first blog post, so-so-so, record here, accumulate! Come on

  

C # Chart about updating sensor data in real time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.