Dynamic invocation of the SPARROW.CHART.WPF control

Source: Internet
Author: User

Recently you need to display the curve in a WPF program, feeling SPARROW.CHART.WPF control is good (http://sparrowtoolkit.codeplex.com/), a fully open source control support, can be downloaded through NuGet. The examples in the source code are fully implemented in MVVM, and the requirement in my project is to create the control entirely through code, binding the data through the code, so it's simple to implement a basic example:

First, top a CPU class (from Sparrow source code):

 Public classCPU {PrivateDateTime time;  PublicDateTime Time {Get{returnTime ;} Set{time =value;} }        Private Doublepercentage;  Public DoublePercentage {Get{returnpercentage;} Set{percentage =value;} }        Private DoubleMemoryusage;  Public DoubleMemoryusage {Get{returnMemoryusage;} Set{memoryusage =value;} }         PublicCPU () {} PublicCPU (DateTime time,DoublePercentageDoublememoryusage) {             This. Time =Time ;  This. Percentage =percentage;  This. Memoryusage =Memoryusage; }

The random data is then generated by a function:

Private voidCreatesomedata () {DateTime dt=DateTime.Now; System.Random rad=NewRandom (System.DateTime.Now.Millisecond);  for(intn=0;n< -; n++) {DT=dt. AddSeconds (1); CPU CPU=NewCPU (Dt,rad. Next ( -),Wuyi);            M_listcpu.add (CPU); }        }

Finally, the chart control is dynamically created by code:

Createsomedata (); //Form Load EventsSparrowchart chart =NewSparrowchart (); Datetimexaxis Xaxis=NewDatetimexaxis (); Xaxis. Interval="0:0:1"; Chart. Xaxis=Xaxis; Xaxis. Visibility=visibility.collapsed; Linearyaxis YAxis=NewLinearyaxis (); Chart. YAxis=YAxis; YAxis. MinValue=0; YAxis. MaxValue= -; Lineseries ser=Newlineseries (); Chart.            Series.add (Ser); Ser. XPath=" Time"; Ser. Ypath="Percentage"; Ser. Pointssource=m_listcpu; ROOTLAYOUT.CHILDREN.ADD (chart);

The program runs as follows:

Dynamic invocation of the SPARROW.CHART.WPF control

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.