This is the discussion forum for OxyPlot.
For bugs and new features, use the issue tracker located at GitHub.
Also try the chat room!

Mistake in documentation

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

TonHadry wrote at 2014-02-14 13:38:

In WPF example located here:
http://www.oxyplot.org/doc/HelloWpf.html

There is same code for "Create view model" and for "Create View"...

objo wrote at 2014-02-14 15:56:

Thanks, I have removed the duplicate code. The code-behind of the window class needs no changes.

Plot Location/Size issue

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

imaloop wrote at 2013-11-23 16:29:

Hello,
I seem to have an issue fixing the location and size of the Plot. is this normal or al i missing something?

My code is like this:
GPlot.Model = new PlotModel();
GPlot.Dock = DockStyle.Fill;
GPlot.Enabled = true;
GPlot.Parent = Top_Tabs.TabPages[2]; // Putting it on a Tab

// At this point the Location And Size of GPlot, are those of the containing parent

GPlot.Location = new System.Drawing.Point(279, 224);
GPlot.Size = new System.Drawing.Size(10, 10);

// Last Two lines had no effect.

this.Matlab.Controls.Add(GPlot);
thank you

imaloop wrote at 2013-11-23 16:39:

Ok, i found out i forgot the Docking to Fill.

Plot Model not rising INotifyPropertyChanged event

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

eZegpi wrote at 2013-09-30 15:07:

Hi, I've just discovered OxyPlot and it really looked like a great tool, but i'm having some trouble getting it up and running, specifically, when I update the plot model it does not rises the property changed event, and therefore it does not plot anything.

Here is the relevant xml
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"

<oxy:Plot Model="{Binding PlotData}" Margin="466,67,123,199"></oxy:Plot>
and the associated code to update PlotData
private PlotModel PlotData = new PlotModel();

            var temp = new PlotModel("Inter");
            var al1 = new OxyPlot.Series.LineSeries("Inter");

            for (int i = 0; i < Curve.GetLength(0); i++)
            {
                al1.Points.Add(new DataPoint(Curve[i, 1], Curve[i, 2]));
            }

            temp.Series.Add(al1);
            temp.Axes.Add(new OxyPlot.Axes.LinearAxis(OxyPlot.Axes.AxisPosition.Bottom, 0, maxX, "X Axis"));
            temp.Axes.Add(new OxyPlot.Axes.LinearAxis(OxyPlot.Axes.AxisPosition.Left, Min, Max, "Y Axis"));
            PlotData = temp;
I suspected that PlotData was not updating correctly, but if I do
Console.WriteLine(PlotData.ToString());
it correctly prints "Inter", if I call that same instruction before the assignment it prints a null line.

Can anyone help me to find my mistake?

Thanks a lot

everytimer wrote at 2013-09-30 17:44:

Use PlotData.RefreshPlot(true); when you want to update the plot. Good luck

eZegpi wrote at 2013-09-30 22:53:

Hi, using your suggestion and setting the bindings to
<oxy:Plot Model="{Binding Source={StaticResource viewModel}, Path=PlotData}"  Margin="466,67,123,199"></oxy:Plot>
I got it to work.

Thank you very much!!

Trouble getting plot to refresh

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

willmoore88 wrote at 2013-07-11 10:43:

My xaml defining my plot.
    <Grid Style="{StaticResource ContentRoot}">
        <oxy:Plot x:Name="CloudLayerPlot" Model="{Binding CloudLayerPlotModel}" Width="600" Margin="0,0,0,0" />
    </Grid>
Some of the code behind this XAML page.
    public PlotModel CloudLayerPlotModel { get; set; }

    public cloudDetectionGraph()
    {
        InitializeComponent();
        DataContext = this;
    }
I then call this code:
        makeCloudLayerPlotModel();
private void makeCloudLayerPlotModel()
        {
            var end = new DateTime();
            end = DateTime.Now;

            var start = new DateTime();
            start = end.AddDays(-1);

            // Create data collection
            var data = new Collection<DateValue>();
            var date = start;

           // Other code here - removed as it's quite long

            plotModel1.Series.Add(lineSeries1);
            plotModel1.Series.Add(lineSeries2);
            plotModel1.Series.Add(lineSeries3);
            plotModel1.Series.Add(lineSeries4);
            CloudLayerPlotModel = plotModel1;
            CloudLayerPlotModel.RefreshPlot(true);
        }
I've tried using RefreshPlot() in different places, ie. after when I call my function to make the plotmodel. I've also tried using invalidateplot() but no joy there either. Sure it's something i'm just overlooking!

When I call this function the first time, the plot is drawn correctly, subsequent calls don't though.

raphay wrote at 2013-07-11 14:06:

I think it is just a binding problem, you should implement INotifyPropertyChanged for your main class:
YourClass :  INotifyPropertyChanged
{

          public event PropertyChangedEventHandler PropertyChanged;


        PlotModel cloudLayerPlotModel;
       public PlotModel CloudLayerPlotModel { 
             get{ return cloudPlotModel ; }
             set
              {
                    cloudPlotModel = value;
                    OnPropertyChanged("CloudLayerPlotModel");
              }
        }

       protected void OnPropertyChanged(string name)
      {
                 PropertyChangedEventHandler handler = PropertyChanged;
                 if (handler != null)
                 {
                     handler(this, new PropertyChangedEventArgs(name));
                 }
      }
}
I hope this will resolve your problem

willmoore88 wrote at 2013-07-11 14:45:

Thank you so much!

Magnitude axis of a polar plot with labels

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

aec wrote at 2012-08-28 22:57:

Hi objo. Is it possible to have a magnitude axis of a polar plot with labels?


objo wrote at 2012-08-29 06:41:

I don't think that was implemented yet, but the MagnitudeAxis should support drawing the tick labels.

I guess you need some control on the placement of the labels? 


aec wrote at 2012-08-29 21:06:

No, not really. It was only a question for reasons of consistency because every axis type has labels except the magnitude axis.


SAlexander wrote at 2013-10-10 23:22:

Haya!
Labels are really required on scientific graph.
Magnitude values are not always normalized, It is strange not to be able to read value from the graph.
Or I am wrong and numerical labels can be shown? I have spent a lot of time trying to locate them.

If linear and polar axis can be shown at the same time, that will work.
(Similar problem in this post https://oxyplot.codeplex.com/discussions/434932)

objo wrote at 2013-10-11 08:17:

Yes, this should be implemented! I have added the issue https://oxyplot.codeplex.com/workitem/10087

Slow loading graphs using WPF

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

willmoore88 wrote at 2013-08-13 10:30:

Hi. I'm using Oxyplot in a WPF project and am finding that my graphs are taking a while to load / update once there is only a few hundred points in them.

I am plotting 1-4 scatter series onto a time / linear graph. The ItemsSource is set to a collection of DateValues - pretty much a copy of whats in one of the examples.

Any ideas why I'm experiencing this slow down?

everytimer wrote at 2013-08-13 20:07:

What MarkerType are you using? I've realized that the performance can vary noticeably. Try to use "Cross" in MarkerType. Good luck

willmoore88 wrote at 2013-08-14 09:02:

var lineSeries1 = new LineSeries("Cloud 1")
            {
                Color = OxyColors.Transparent,
                MarkerFill = OxyColors.Black,
                MarkerStroke = OxyColors.Black,
                MarkerType = MarkerType.Circle,
                MarkerSize = 1.5,
                StrokeThickness = 1,
                DataFieldX = "Date",
                DataFieldY = "Value1",
                ItemsSource = data
            };
            var lineSeries2 = new LineSeries("Cloud 2")
            {
                Color = OxyColors.Transparent,
                MarkerFill = OxyColors.Black,
                MarkerStroke = OxyColors.Black,
                MarkerType = MarkerType.Circle,
                MarkerSize = 1.5,
                StrokeThickness = 1,
                DataFieldX = "Date",
                DataFieldY = "Value2",
                ItemsSource = data
            };
            var lineSeries3 = new LineSeries("Cloud 3")
            {
                Color = OxyColors.Transparent,
                MarkerFill = OxyColors.Black,
                MarkerStroke = OxyColors.Black,
                MarkerType = MarkerType.Circle,
                MarkerSize = 1.5,
                StrokeThickness = 1,
                DataFieldX = "Date",
                DataFieldY = "Value3",
                ItemsSource = data
            };
            var lineSeries4 = new LineSeries("Cloud 4")
            {
                Color = OxyColors.Transparent,
                MarkerFill = OxyColors.Black,
                MarkerStroke = OxyColors.Black,
                MarkerType = MarkerType.Circle,
                MarkerSize = 1.5,
                StrokeThickness = 1,
                DataFieldX = "Date",
                DataFieldY = "Value4",
                ItemsSource = data
            };
            var lineSeries5 = new LineSeries("Vertical Visibility")
            {
                Color = OxyColors.Transparent,
                MarkerFill = OxyColors.Transparent,
                MarkerStroke = OxyColors.Blue,
                MarkerType = MarkerType.Square,
                MarkerSize = 1.5,
                StrokeThickness = 1,
                DataFieldX = "Date",
                DataFieldY = "Value5",
                ItemsSource = data
            };
Mainly circles, with only the occasional square. I'll give cross a go but I really need circles!

Question about accessing the plot in MVVM

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

DrStrangeLove wrote at 2014-03-15 04:16:

My plot is created entirely in the view and is bound with data from the view model. When the data sets that are bound, my plot is not refreshing to redraw the data within the correct scale if I zoom or toggle the visibility of a line. So my question is how can I make sure that my graph resets to the correct size when I have zoomed or panned? If I press 'A' to reset the view before I switch the data binding the graph behaves correctly, it is just in the case when I do anything to the graph.

Any help is greatly appreciated and I hope I explained this question thoroughly.

DrStrangeLove wrote at 2014-03-26 17:56:

The real question I have is how can I access the plot that is entirely set up in the xaml, through my view model, because I need to refresh the plot when the data set changes so that they axises update correctly when the data changes.

tibel wrote at 2014-03-26 19:21:

Why you set up the plot in XAML when using MVVM?

objo wrote at 2014-03-26 20:25:

The Plot control has an InvalidatePlot method that can be called to invalidate and update the data.
There is also a command binding on the Plot.ResetAxesCommand command (I think this should be refactored to PlotCommands.ResetAxes)
You can also bind to the InvalidateFlag property - when the value is changed the plot is invalidated. I am not sure if this is a good feature, would like to get feedback on this one..
I think it is possible to use an attached property if you want to bind to the actual PlotModel.

objo wrote at 2014-03-26 20:35:

The command is changed to PlotCommands.ResetAxes. See example in the "ExportDemo".

DrStrangeLove wrote at 2014-03-27 15:06:

Thank you for the answer this was a big help.

Report text color

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

everytimer wrote at 2013-08-15 11:34:

I need to export a report and be able to change the color of some words. I've noticed that the Paragraph style is used when the report is actually being written, so I can't change it to the desired color, and then switch back to the default (black) because all will be written in black.

I've tried to convert HeaderStyles to a list instead of an array but that gave me a lot of troubles and finally a rare exception occurred. After that I just tried to increase HeaderStyles array to 25 (I will need 20 different colors + let intact the 5 default header style).

The problem is that if I set the array bigger than 9 a null reference exception occurs. I wonder if there is a better way of implementing this requirement and if not what can I do for being able to increase the array size of HeaderStyles to 25.


inside a loop:
  ParagraphStyle myStyle = new ParagraphStyle { BasedOn = reportStyle.DefaultStyle };
                               reportStyle.HeaderStyles[4 + myStyleSelector ] = myStyle ;
                              report.AddHeader(5 + myStyleSelector , "my text");
after:
   using (var w = new PdfReportWriter((dlg.FileName)))
                       {
                           w.WriteReport(report, reportStyle);
                           
                       }

objo wrote at 2013-08-15 17:05:

HeaderStyles should only be used for headers. We could change the array to a list, but normally 5 or 6 (html limit) should be enough.
To change the color on parts of a paragraph, we need to implement Inline elements with a Style property. I have added an issue:
https://oxyplot.codeplex.com/workitem/10071

Check if point was selected

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

Xgamer wrote at 2012-05-06 15:17:

Hello,

I would like to ask how can I check if point from series was selected?Is it possible to somehow check if default point mousehover event was invoked?

I am newbie in using oxyplot library :)


objo wrote at 2012-05-07 18:05:

The mouse events that was just added contains a "HitTestResult" in the event arguments.

The hit test results contains a property "Index" which should give you the index of the point that was clicked on. Note that the index is of type double; if the index = 4.5 it means that the user clicked on the line half-way between point 4 and 5 (in the case of a LineSeries). You have to decide if it is close enough, and then use Math.Round(Index) to get the index of the nearest point. 

Note that selection is not completely implemented yet.


viklele wrote at 2012-10-12 10:35:

I know my reply is a bit late, but here is a code fragment for anyone to use:

 

// Subscribe to the event
plot.Model.MouseDown += new EventHandler<OxyPlot.OxyMouseEventArgs>(plotModel_MouseDown);


// event handler
void plotModel_MouseDown(object sender, OxyPlot.OxyMouseEventArgs e)       
{
   Plot plot = sender as Plot;
   switch (e.ChangedButton)
   {
      case OxyPlot.OxyMouseButton.Left:
         OxyPlot.Series series = plot.GetSeriesFromPoint(e.Position, 10);
         if (series != null)
         {
            OxyPlot.TrackerHitResult result = series.GetNearestPoint(e.Position, true);
            if (result != null && result.DataPoint != null)
            {
               // data point nearest to the click
               OxyPlot.IDataPoint dataPoint = result.DataPoint;

            }
        }
        break;
   }
}

LogarithmicAxis does not raise AxisChanged Event when zooming

Oystein Bjorke 10 years ago 0
This discussion was imported from CodePlex

WeirdNoise wrote at 2013-08-13 20:38:

Obviously a bug; the overridden ZoomAt-Method in LogarithmicAxis.cs does not raise the Event.

I think you would need to add a RaiseAxisChanged-Method in the base Axis Class to allow the child class to raise the event?

WeirdNoise wrote at 2013-08-13 21:05:

My way of fixing it - and also dealing with another bug, which causes the AxisChanged-Event to fire before the limits are actually updated:
    Public Class LogAxis
        Inherits Axes.LogarithmicAxis

        Public Event ActualAxisChanged(min As Double, max As Double)

        Public Overrides Sub ZoomAt(factor As Double, x As Double)
            MyBase.ZoomAt(factor, x)
            RaiseEvent ActualAxisChanged(ViewMinimum, ViewMaximum)
        End Sub

        Private Sub Axis_Changed() Handles MyBase.AxisChanged
            RaiseEvent ActualAxisChanged(ViewMinimum, ViewMaximum)
        End Sub
    End Class

objo wrote at 2013-08-14 07:02:

Thank you! I have fixed the bug and added an example to verify that it works.

objo wrote at 2013-08-14 07:04:

Note that the UpdateActualMaxMin(); method is called - you should use ActualMaximum and ActualMinimum to get the actual limits.

WeirdNoise wrote at 2013-08-14 08:16:

Wow, that was fast, thanks a lot!