3

I'm working with OxyPlot in WPF and have some problems. I'm trying to create an app and want to use OxyPlot to create a chart. Everything works except that the plot/the data won't show up. I can't seem to figure out why.

Here is some of my xaml code:

<UserControl x:Class="myNameSpace.MainPanel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:app="clr-namespace:myNameSpace"
             xmlns:oxy="http://oxyplot.org/wpf"
             mc:Ignorable="d"
             d:DesignHeight="1200"
             d:DesignWidth="1920">
    <UserControl.DataContext>
        <local:MainViewModel/>
    </UserControl.DataContext>
    ....
    <oxy:Plot Title="{Binding Title}" Margin="760,689,606,228" Width="504" Height="283">
            <oxy:Plot.Series>
                <oxy:LineSeries ItemsSource="{Binding Points}"/>
            </oxy:Plot.Series>
        </oxy:Plot>

and my MainViewPanel class looks like this:

public class MainViewModel
        {
            public MainViewModel()
            {
               this.Title = "Example 2";
               this.Points = new List<DataPoint>
                              {
                                  new DataPoint(0, 4),
                                  new DataPoint(10, 13),
                                  new DataPoint(20, 15),
                                  new DataPoint(30, 16),
                                  new DataPoint(40, 12),
                                  new DataPoint(50, 12)
                              };
            }

            public string Title { get; private set; }

            public IList<DataPoint> Points { get; private set; }
     }

This is how the chart looks like when I run my code

Screen shot

7
  • The code you've provided works OK for me. It's a bit of an outside chance but I assume that the Points list in the VM is a list of OxyPlot.DataPoint and not a list of a DataPoint from somewhere else. Commented Jun 22, 2017 at 12:42
  • Ignore my previous comment, looking at your picture again, it looks like the Title is not binding either. Commented Jun 22, 2017 at 13:34
  • 2
    Are you sure that the MainViewModel referenced in your xaml is of the correct type. I don't see local namespace prefix defined. If the MainViewModel is in the AnnaEmilie namespace, change local:MainViewModel to app:MainViewModel Commented Jun 22, 2017 at 13:40
  • Thank you so much for your help! It was the local namespace prefix that was the problem. It works fine now. Commented Jun 26, 2017 at 9:18
  • 1
    It's very great that the answer was found. I think it will be nice if someone post the answer to the Q. Commented Jun 29, 2017 at 10:10

2 Answers 2

3

I don't see local namespace prefix defined. If the MainViewModel is in the AnnaEmilie namespace, change local:MainViewModel to app:MainViewModel

Sign up to request clarification or add additional context in comments.

Comments

0

Remove margins because they obscure your graph form being visible.

<oxy:Plot Title="{Binding Title}" Width="504" Height="283">
    <oxy:Plot.Series>
        <oxy:LineSeries ItemsSource="{Binding Points}"/>
    </oxy:Plot.Series>
</oxy:Plot>

3 Comments

Not sure this answers Anna's question. She is seeing the graph, it just doesn't have any data points. I think the large margins are being used for absolute positioning.
You're right @JanisS, I can only see one half of my graph when I use margins now (it worked before). But if I remove it I can't have absolute positioning and the graph does not end up where I want it to be.
@Anna try using relative positioning. One of the easiest ways is to "stack up" your elements and then by use of margins and padding position them as you would expect or use Grid (codeproject.com/Articles/140613/…).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.