Creating Chart using DataVisualization.Charting in .NET 4.0
I'm attempting to user System.Windows.Forms.DataVisualization.Charting to create a line chart. I've been using the System.Wind开发者_如何学Goows.Controls.DataVisualization.Toolkit for a while now but would like to get rid of all of my .Net 3.5 references. I cannot find any sources for examples of charts using DataVisualization.Charting
Using System.Windows.Controls.DataVisualization.Toolkit...
<DVC:Chart Name="mcChart" Width="Auto" Height="225" Padding="0" Margin="0,-5,0,0" >
<DVC:Chart.Series>
<DVC:LineSeries x:Name="lsActual" Title=" Expenditures" IndependentValueBinding="{Binding Month}" DependentValueBinding="{Binding Amt}" DataPointStyle="{StaticResource redLineDataPoint}" />
<DVC:LineSeries x:Name="lsBudget" Title=" Budget" IndependentValueBinding="{Binding Month}" DependentValueBinding="{Binding Amt}" DataPointStyle="{StaticResource blueLineDataPoint}"/>
<DVC:LineSeries x:Name="lsProjection" Title=" Projection" IndependentValueBinding="{Binding Month}" DependentValueBinding="{Binding Amt}" DataPointStyle="{StaticResource greenLineDataPoint}" />
</DVC:Chart.Series>
</DVC:Chart>
System.Windows.Forms.DataVisualization.Charting...
?
References
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:CHR="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
You can use the new (FW4.0) charting controls, but they are WindowsForms controls, which means you have to use the <WindowsFormsHost>
container:
- Add a reference to
WindowsFormsIntegration
- Add a reference to
System.Windows.Forms.DataVisualization
Add the following namespace:
xmlns:charting="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization"
Also, there are some things you have to keep in mind with hybrid applications.
Besides the above, I think the WindowsForms version of the charting controls is a bit better designed. I'm going to give them a try in a WPF application.
More help:
- Using Chart Controls
- Chart Controls - Helpful Links
- Chart Controls for .NET Framework Forum
- Microsoft Chart Controls for .NET Framework Documentation (not sure if it's the right version)
- Another possibly useful post
Download the "Samples Environment"! It has a truckload of examples and guides. I've only had two problems with it: running the executable directly and problems when the path had a #
in it.
You have to use the toolkit.
精彩评论