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

  • Home
  • SEARCH
  • 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 3842372
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:47:03+00:00 2026-05-19T15:47:03+00:00

I have a WPF chart currently displaying an Area series. I need to allow

  • 0

I have a WPF chart currently displaying an Area series. I need to allow a user the ability to click on the chart and add a new point for a Line series. The problem I’m having is I can’t seem to find a way to convert the point from a MouseButtonEventArgs to a LineDataPoint.

private void chtPowerFlowMap_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        Point p = e.GetPosition(chtPowerFlowMap);

        points.Add(p); //Issue here is this will return a point in screen coordinates and not in chart coordinates

        ls.ItemsSource = points; //ls is an existing lineseries and points is a List<Point> object

        chtPowerFlowMap.Series.Add(ls);
    }

Thanks in advance.

  • 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-19T15:47:04+00:00Added an answer on May 19, 2026 at 3:47 pm

    Here is a complete solution. You can click anywhere on the chart and there will be a new point at that palce.

    MainWindows.xaml

    <chart:Chart x:Name="chart" MouseLeftButtonDown="Chart_MouseLeftButtonDown">
            <chart:LineSeries ItemsSource="{Binding}" x:Name="lineSeries"
                              DependentValuePath="Value"
                              IndependentValuePath="Date"/>
    </chart:Chart>
    

    MainWindow.xaml.cs

    public partial class MainWindow : Window
    {
        private ObservableCollection<Item> items;
    
        public MainWindow()
        {
            InitializeComponent();
            Random rd = new Random();
    
            items = new ObservableCollection<Item>(
                    Enumerable.Range(0, 10)
                    .Select(i => new Item
                    {
                        Date = DateTime.Now.AddMonths(i - 10),
                        Value = rd.Next(10,50)
                    }));
            this.DataContext = items;
        }
    
        public class Item
        {
            public DateTime Date { get; set; }
            public double Value { get; set; }
        }
    
        private void Chart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var p = Mouse.GetPosition(this.lineSeries);
            //ranges in the real values
            var left = items.Min(i => i.Date);
            var right = items.Max(i => i.Date);
            var top = items.Max(i => i.Value);
            var bottom = items.Min(i => i.Value);
    
            var hRange = right - left;
            var vRange = top - bottom;
    
            //ranges in the pixels
            var width = this.lineSeries.ActualWidth;
            var height = this.lineSeries.ActualHeight;
    
            //from the pixels to the real value
            var currentX = left + TimeSpan.FromTicks((long)(hRange.Ticks * p.X / width));
            var currentY = top - vRange * p.Y / height;
    
            this.items.Add(new Item { Date = currentX, Value = currentY });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a wpf column series chart and I have more than 15 columns.
So, I have a WindowsFormsHost control in my WPF app (hosting a Dundas Chart)
I have several wpf pages with update/delete/add buttons. I want to display to the
I am using the new WPF toolkit's Chart to plot large data sets. I
i have problem to correctly bind data to WPF Chart. When i'm setting ItemsSource
I have a chart in WPF with a lot of labels. The text on
I have a WPF DataGrid bound to some entities (Entity Framework 4+). User then
I have a WPF click-once application that makes use of an unmanaged dll. When
I have WPF ListBox which is bound to a ObservableCollection, when the collection changes,
I have a WPF project and I'm trying to setup a NAnt build script

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.