Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:58+00:00 2026-05-27T18:45:58+00:00

Ok so I am just practicing what is probably some very basic stuff with

  • 0

Ok so I am just practicing what is probably some very basic stuff with charts in wpf. I am fairly new to linq and wpf, so I apologize in advance if this is a silly question. I’ve got my LINQ to entity query returning all columns, I want to select two of the columns (Month (string), Points(int)) throw them into a dictionary, and then binding that to my chart..

Here is my XAML::

<Window x:Class="Chart.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:DV="clr-namespace:System.Windows.Controls.DataVisualization;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    xmlns:DVC="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <DVC:Chart Name="testchart" Title="Statistics" Width="500" Height="300" LegendTitle="Stats">
        <DVC:Chart.Series>
            <DVC:BarSeries Title="Points"
                           IndependentValueBinding=""
                           DependentValueBinding="">
            </DVC:BarSeries>
        </DVC:Chart.Series>
    </DVC:Chart>
</Grid>

And here is the code behind:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.DataVisualization.Charting;

namespace Chart
{

public partial class MainWindow : Window
{
    Dictionary<string, int> _data = new Dictionary<string, int>();

    public MainWindow()
    {
        InitializeComponent();
        using (CE ctx = new CE())
        {
            var query = (from r in ctx.ChartOnes
                           select r).ToDictionary(k => k.Month);
        }


    }

}
}

Thanks Dessus for your timely response! I will play around with your suggestions today. I did get some help from a co-worker yesterday and he was able to show me how to get it to work. Here is the edited code snippets:

        <DVC:Chart Name="testchart" Title="Statistics" Width="500" Height="300" LegendTitle="Stats">
        <DVC:Chart.Series>
                <DVC:ColumnSeries Title="Points"
                           IndependentValueBinding="{Binding Path=Key}"
                           DependentValueBinding="{Binding Path=Value.Points}">
                </DVC:ColumnSeries>
            </DVC:Chart.Series>
    </DVC:Chart>

and the code-behind:

        private void LoadBarChartData()
    {
        CE ctx = new CE();

        var query = (from r in ctx.ChartOnes
                     select new { Points = r.Points, Month = r.Month }).ToDictionary(k => k.Month);

        ((ColumnSeries)testchart.Series[0]).ItemsSource  = query;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:45:58+00:00Added an answer on May 27, 2026 at 6:45 pm

    You should look up a model view view-model (MVVM) example of how to do databinding in WPF for chart controls (see: http://geekswithblogs.net/BillSontag/archive/2009/10/31/wpf-2-way-data-binding.aspx). The way you are doing your query in code behind will make it annoying (but can work) to get a reference to your control, but MVVM will make life easier once you get it working and get used to it. Your Linq query appears like it should output to a datatable as opposed to a dictionary.

    Side Note: Any updates to the underlying LINQ collections will not trigger updates in your chart control. For that you would need something like: http://bindablelinq.codeplex.com/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using g++ on fedora linux 13. I'm just practicing some exercises from my
I'm practicing some XSL and using this XML document as a simple example: <?xml
I was just practicing some coding and noticed that I was able to use
I'm on railcasts just practicing some rails and have come across something I'm trying
i just started practicing android and sqlite database. i came across a very strange
I'm just starting out with rails and I'm practicing the basic ruby commands, one
gcc I am just getting back into c programming and I am just practicing
I just started practicing TDD in my projects. I'm developing a project now using
Just looking for the first step basic solution here that keeps the honest people
I just started developing on Android. I'm practicing with a Tablayout tutorial in API

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.