Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

Below is my chart window xaml code

XML
<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
VB
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
VB
Dim g As New GraphWin
    g.ShowChart()

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

Please tell me how to do this..
Posted
Updated 2-Dec-13 17:36pm
v4

1 solution

 
Share this answer
 
Comments
[no name] 3-Dec-13 2:20am    
Can you suggest any link using fetching data from database and display it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900