如何在WPF中创建图表 [英] How to create chart in WPF

查看:106
本文介绍了如何在WPF中创建图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



下面是我的图表窗口xaml代码



Hi all

Below is my chart window xaml code

<Window x:Class="GraphWin"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="Graph" Height="560" Width="630" xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit" Loaded="Window_Loaded">
    <Grid>
        <chartingToolkit:Chart DataContext="1,10 2,20 3,30 4,40" HorizontalAlignment="Left" Margin="12,12,0,0" Name="Chart1" Title="Chart Title" VerticalAlignment="Top" Height="352" Width="584">
            <chartingToolkit:ColumnSeries DependentValuePath="X" IndependentValuePath="Y" ItemsSource="{Binding}" />

            <chartingToolkit:PieSeries Name="PieChart" DependentValuePath="Value"  IndependentValuePath="Key" ItemsSource="{Binding}" 

            IsSelectionEnabled="True" />
            
        
        </chartingToolkit:Chart>
    </Grid>
</Window>



这是后端代码


and this is the back end code

Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System
Imports System.Globalization
Imports System.Collections.ObjectModel
Imports System.Runtime.Remoting.Contexts
Public Class GraphWin
    Private con As New SqlConnection("Data Source=501013-PC;Database=nand00132013;User Id=sa;Password=1234")


    Sub ShowChart()
        Dim MyValue As New List(Of KeyValuePair(Of String, Integer))()
        Dim cmd As New SqlCommand("select top(5) AgencyName, Amount from SuppReport", con)
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable
        da.Fill(dt)
        For Each item As DataRow In dt.Rows
            MyValue.Add(New KeyValuePair(Of String, Integer)(dt.Rows(0)("AgencyName"), dt.Rows(0)("Amount")))
        Next
        PieChart.DataContext = MyValue
    End Sub

    Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        ShowChart()
    End Sub
End Class





在这个主窗口,我有一个按钮,点击图形窗口将打开



At this main window i have a button and on click the graph window will open

Dim g As New GraphWin
    g.ShowChart()



但它显示了这个

http://i40.tinypic.com/2jbqh69.png [ ^ ]



请告诉我怎么做..


but it's showing this
http://i40.tinypic.com/2jbqh69.png[^]

Please tell me how to do this..

推荐答案

我建​​议你读这个:

使用WPF生成图表 [ ^ ]

WPF中的图表 [ ^ ]

WPF工具包图表控件(线条,条形,面积,饼图,列系列)演示 [ ^ ]
I would suggest you to read this:
Generating Graphs with WPF[^]
Charting in WPF[^]
WPF Toolkit Charting Controls (Line, Bar, Area, Pie, Column Series) Demo[^]


这篇关于如何在WPF中创建图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆