I. Basic Introduction
Silverlight toolkit is a Microsoft-released control set based on Microsoft-Public License (MS-PL) license agreement. The MS-PL license agreement allows commercial or non-commercial release, so we can easily apply this toolkit to the Silverlight project.
To use Silverlight Toolkit: First, you need to download the latest DLL file from http://www.codeplex.com/silverlightorSource codeAnd add references to your Silverlight project. Finally, you can create the control provided in the Toolkit.
Ii. Use chart controls
Use the XAML language or XAML +CodeExamples of using chart controls are more common. This article will briefly introduce how to use chart by using code programming.
Chart is a widget used in Silverlight toolkit to display data in graphs and tables. It is located in Microsoft. Windows. Controls. datavisualation. Charting assembly.
When using the chart control:
First, add a reference to the Microsoft. Windows. Controls. datavisualation. Charting namespace.
Code
UsingMicrosoft. Windows. Controls. datavisualization. charting;
Second, create the chart control and set the appearance attributes;
Code
Chart chart= NewChart ();
Chart. setvalue (grid. rowproperty,1);
This. Layoutroot. Children. Add (Chart );
Step 3: Create dynamicseries data. charts in the Silverlight Toolkit can represent barseries, columnseries, scatterseries, and lineseries ), when using these graphs, you must first create the corresponding series.
Code
Pieseries PS = New Pieseries ();
PS. itemssource = New Int [] { 1 , 2 , 30 , 50 };
Finally, add the created dynamicseries to the itemsource of the chart.
Code
Chart. Series. Add (PS );
ProgramThe running result is as follows:
When using data in a project, it should be a little more complex. First, we need to understand two concepts:
Independentvalue and dependentvalue
Independentvalue and dependentvalue are bound through the independentvaluebinding and dependentvaluebinding attributes respectively. Independentvalue indicates the name of the quantity to be evaluated, while dependentvalue indicates the number of each independentvalue. For example, in the above example, {, 3, 4} is the independentvalue, and the corresponding dependentvalue is, 30, 50 }.
Note the following when using chart:
Linechart and scaterchart dataLineseries. indepdenvalueAndScatterseries. indepdenvalueIt must be a comparable amount.
Code
Lineseries = New Lineseries ();
System. Windows. Data. Binding keybinding = New System. Windows. Data. Binding ();
Keybinding. Path = New Propertypath ( " Key " );
Lineseries. independentvaluebinding = Keybinding;
System. Windows. Data. Binding valuebinding = New System. Windows. Data. Binding ();
Valuebinding. Path = New Propertypath ( " Value " );
Lineseries. dependentvaluebinding = Valuebinding;
Lineseries. itemssource= NewKeyvaluepair<Datetime,Int>[] {
New keyvaluepair datetime, int > (datetime. now, 9 ),
New keyvaluepair datetime, int > (datetime. now. adddays ( 1 ), 8 ),
New keyvaluepair datetime, int > (datetime. now. adddays ( 3 ), 6 ),
New keyvaluepair datetime, int > (datetime. now. adddays ( 2 ), 9 ),
NewKeyvaluepair<Datetime,Int>(Datetime. Now. adddays (4),8)
};
Chart. Series. Add (lineseries );
The running result of the above Code: