This topic describes the steps necessary to build a simple Wpf application using Nevron Chart for .NET.
1. Open Microsoft Visual Studio .NET.
2. On the File / New Project select "Visual C#", then "Windows" from the tree of installed templates. Then select "WPF Application" from the list on the right.
4. [Optional] Change the application name from WpfApplication[n] to NChartTest.
5. Click OK.
6. Open the Toolbox. If it's not visible open it from the View\Toolbox menu item.
7. Locate the Nevron Chart Wpf tab and expand it.
8. Drag and drop the NChartControl item on the form.
9. Start the application. The form must display an empty chart.
10. Close the application and then open the source code for MainWindow.xaml.cs.
11. Add the following lines in the beginning of the file:
C# |
Copy Code
|
---|---|
using Nevron.GraphicsCore; using Nevron.Chart; using Nevron.Chart.Windows; using Nevron.Chart.Wpf; |
Visual Basic |
Copy Code
|
---|---|
Imports Nevron.GraphicsCore Imports Nevron.Chart Imports nevron.Chart.Windows Imports Nevron.Chart.Wpf |
12. In the main window constructor add the following code:
C# |
Copy Code
|
---|---|
nChartControl1.Controller.Tools.Add(new NSelectorTool()); nChartControl1.Controller.Tools.Add(new NTrackballTool()); NPieChart chart = new NPieChart(); nChartControl1.Charts.Clear(); nChartControl1.Charts.Add(chart); chart.Enable3D = true; chart.Width = 70; chart.Depth = 10; chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveElevated); chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyCameraLight); NPieSeries pie = (NPieSeries)chart.Series.Add(SeriesType.Pie); pie.PieStyle = PieStyle.SmoothEdgePie; pie.LabelMode = PieLabelMode.SpiderNoOverlap; pie.AddDataPoint(new NDataPoint(12, "Cars")); pie.AddDataPoint(new NDataPoint(42, "Trains")); pie.AddDataPoint(new NDataPoint(56, "Airplanes")); pie.AddDataPoint(new NDataPoint(23, "Buses")); pie.AddDataPoint(new NDataPoint(32, "Bikes")); pie.AddDataPoint(new NDataPoint(29, "Boats")); NStyleSheet styleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.NevronMultiColor); styleSheet.Apply(nChartControl1.Document); nChartControl1.Refresh(); |
Visual Basic |
Copy Code
|
---|---|
nChartControl1.Controller.Tools.Add(New NSelectorTool()) nChartControl1.Controller.Tools.Add(New NTrackballTool()) Dim chart As NPieChart = New NPieChart() nChartControl1.Charts.Clear() nChartControl1.Charts.Add(chart) chart.Enable3D = True chart.Width = 70 chart.Depth = 10 chart.Projection.SetPredefinedProjection(PredefinedProjection.PerspectiveElevated) chart.LightModel.SetPredefinedLightModel(PredefinedLightModel.ShinyCameraLight) Dim pie As NPieSeries = chart.Series.Add(SeriesType.Pie) pie.PieStyle = PieStyle.SmoothEdgePie pie.LabelMode = PieLabelMode.SpiderNoOverlap pie.AddDataPoint(new NDataPoint(12, "Cars")) pie.AddDataPoint(new NDataPoint(42, "Trains")) pie.AddDataPoint(new NDataPoint(56, "Airplanes")) pie.AddDataPoint(new NDataPoint(23, "Buses")) pie.AddDataPoint(new NDataPoint(32, "Bikes")) pie.AddDataPoint(new NDataPoint(29, "Boats")) Dim styleSheet As NStyleSheet = NStyleSheet.CreatePredefinedStyleSheet(PredefinedStyleSheet.NevronMultiColor) styleSheet.Apply(nChartControl1.Document) nChartControl1.Refresh() |
13. Now start the application again - the chart must display a simple pie chart that you can rotate with the mouse..
14. Congratulations - you've created your first Wpf application using Nevron Chart for .NET!