Binding a cursor to a time source
drakesmith wrote at 2013-01-20 17:39:
I have created an audio waveform plot for a .wav player application. So far, OxyPlot has been fantastic for that. I use a vertical line annotation whose X position is bound to the playback position to track media position within the waveform. The position
is updated every 100mS and the cursor looks great. The problem is that changing LineAnnotation.X at that rate uses 100% CPU.
Is there a better way to create a vertical position marker? A custom tracker seems close, but I want the cursor to move independently of the mouse. I don’t need any text or fancy graphic or mouse interaction, just a thin vertical cursor that overlays the plot.
Thank you.
objo wrote at 2013-01-22 09:34:
Yes, the whole model will be redrawn when changing an annotation. Check that you are not invalidating the data, no need to refresh data bindings when changing an annotation. Also see the Performance section under documentation.
In WPF, you could draw the cursor line in a canvas overlay above the plot control - subscribe to the axis changed events and use the transform methods on the axes to get the correct positions.
drakesmith wrote at 2013-01-22 10:50:
Thanks objo, your recommendation to use a canvas overlay is a reasonable workaround.
I will document those details and submit them back to you for inclusion in your documentation if you so choose.
Namespace prefix "oxy" not defined
morty77 wrote at 2013-09-25 12:42:
This might be a very basic question, but after installing OxyPlot.WPF (and OxyPlot.Core) in NuGet in a new VS 2012 project I can't see any oxyplot controls in the Toolbox. Neither can I add any XAML like in the WPF Example:
<oxy:Plot Model="{Binding MyPlotModel}"/>
Here the compiler complains about the namespace prefix "oxy" not being defined. Have I missed out something?
I would guess I would have to add a line similar to this in the Windows tag?
xmlns:oxy="clr-namespace:OxyPlot.Wpf;assembly=OxyPlot.Wpf"
However, when I do that, I get the error: FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
The C# codebehind works fine.
Thanks.
loic_lopes wrote at 2013-09-25 14:29:
morty77 wrote at 2013-09-26 09:34:
Have you tried to add a reference to System.Core?Hi there,
A reference to System.Core is already there. I tried to search for a System.Core.dll with version 2 but could not find it on my computer. I found 3.5 but I am not sure whether I should delete the existing reference and add this one.
By the way I am targeting .NET Framework 4.5 in my project, and I'm using Visual Studio 2012 Express for Windows Desktop.
objo wrote at 2013-09-26 10:00:
Is your VS 2012 Express up to date? Update 3 is needed for other versions of Visual Studio 2012.
morty77 wrote at 2013-09-26 10:19:
Yes, it's got update 3. Full version number is 11.0.60610.01. Update 3.
I have VS 2010 also running on my computer. I might try to compile it there as well.
morty77 wrote at 2013-09-26 10:38:
VS 2012 Express still gets the error above.
morty77 wrote at 2013-09-26 10:51:
How to update a function plot?
aec wrote at 2012-08-21 14:52:
Hi,
I would like to create plot, which relys on a function rather than on data points. This plot should automatically be updated in case of a change of the x axis. For instance, this should be done when a user zooms out (or in).
Manually, I have done this with text boxes, where you type in xmin and xmax and the graph is updated via data binding. Maybe, it is possible to extend this idea by binding to the minimum and maximum of the x axis. But I don't know how to do this. Has anyone an idea how to tackle this problem?
objo wrote at 2012-08-21 15:46:
Subscribe to the AxisChanged event on the axis. The ActualMaximum and ActualMinimum values are updated before the event is raised, and these values can be used to update the limits of your function series. Then call PlotModel.Refresh(true) (since the plot data was modified) to update the plot.
aec wrote at 2012-08-22 09:17:
Thank you, for your immediate response. I thnk, your solution works fine in case of a pure C# program. But what I like to have is a C#/WPF solution with MVVM pattern. That is, I have
1.) a model for the function f(x). The evaluation of this function yiels the Points and depends on the limits of x: XMin, XMax.
public double XMin { get; set; }
public double XMax { get; set; }
public IList<DataPoint> Points{
get {
return evaluatedPoints; } }
2.) a view model where OnPropertyChanged of the Points and the changed limit is raised.
public IList<DataPoint> Points { get { return model.Points; } }
public double XMax // same for XMin
{
get { return model.XMax; }
set
{
model.XMax = value;
OnPropertyChanged("XMax");
OnPropertyChanged("Points");
}
}
3.) a WPF view where the axis properties are modified. With respect to XMax we have for instance
<oxy:Plot.Axes>
<oxy:LinearAxis Position="Bottom">
<oxy:LinearAxis.Maximum>
<Binding Mode="TwoWay"
Path="XMax"
Source="{StaticResource viewModel}"
UpdateSourceTrigger="PropertyChanged" />
</oxy:LinearAxis.Maximum>
</oxy:LinearAxis>
<oxy:Plot.Axes/>
The problem is that there is no dependency property for ActualMaximum and ActualMinimum. Of course, I could implement this. But I don't like this approach, because than I am modifying your library. As a consequence I have to do this modification for all future versions.
To this end, I would like to ask you, if you can do this?
objo wrote at 2012-08-24 09:12:
I think it could be possible to add an AxisChanged routed event on the OxyPlot.Wpf.LinearAxis. This could pass the events from the OxyPlot.LinearAxis. http://oxyplot.codeplex.com/workitem/9992
It should also be possible to make some read-only dependency properties for ActualMaximum/ActualMinimum, which may get change notifications every time the plot is changed (e.g. panned, zoomed or data changed). http://oxyplot.codeplex.com/workitem/9993
aec wrote at 2012-08-24 11:00:
Hi objo, that would be cool! I am looking forward to this feature!
Zoom not available on axis after switching visibility
Basically, I'm trying to have a feature that allows the user to switch an axis between linear and logarithmic. As suggested by Oystein in gitter, I've created the 2 Axes (one log, one lin), set one to invisible and the other to true and put my series by default to the visible one. Then, when my user clicks on something, I set the visible one to invisible vice versa and switch my series to the visible one.
It works pretty well, but neither the zoom nor the pan on the linear axis is working. I'm wondering if there is something to set at the level of the PlotModel to tell him which axis should be panned & zoomed, but I can't find any option.
Here's my code that does the switch for reference (in a setter of a property, hence the "value"):
var logAxis = this.MyPlot.Axes.Single(x => x.Key == "LogAxis"); var linAxis = this.MyPlot.Axes.Single(x => x.Key == "LinAxis"); linAxis.IsZoomEnabled = linAxis.IsPanEnabled = linAxis.IsAxisVisible = !value; logAxis.IsZoomEnabled = logAxis.IsPanEnabled = logAxis.IsAxisVisible = value; this.MyPlot.Series.Apply( s => {
var series = s as XYAxisSeries; if (series != null) { if (value) { series.XAxisKey = "LogAxis"; } else { series.XAxisKey = "LinAxis"; } } });
disable zooming
steunissen wrote at 2011-07-19 10:49:
First I have to say I absolutely love this great tool !
And I have a question ;-)
When I am on a chart and I want to scroll down (the chart is in a listview) the chart zooms as well. But I want the chart to be fixed, thus disabling the zoom functionality... Can I do this ?
Sander.
objo wrote at 2011-07-19 13:43:
hi Sander, you can set IsZoomEnabled = false to each of your axes, I think this is what you need!
steunissen wrote at 2011-07-19 17:35:
objo wrote:
hi Sander, you can set IsZoomEnabled = false to each of your axes, I think this is what you need!
Ah, I found it...
I was defining my axes in wpf, but there is no IsZoomEnabled property available.
Now I define my axes in code and IsZoomEnabled is available.
The OxyPlot and OxyPlot.WPF namespaces have more or less different objects with identical names... I found that a bit confusing...
objo wrote at 2011-07-20 21:50:
Right, all properties are not yet available in the WPF/SL classes, but this is planned (I hope to be able to share the code on both platforms). I understand it can be a bit confusing with identical names and the two different ways to define the plots, but there are advantages with both methods, so I think it should be kept that way.
Help using scatter plot and Heatmap in Oxyplot winform
Meyip wrote at 2013-04-02 07:25:
Here's what I'm trying to do.
Create a C# Winform App to graph data from the serial port on a Scatter Plot, then a Heat map using Oxyplot.
I've gotten my C# program to read the serial data and output a multidimensional integer array in the form (int[x,y]). Now after copying the code from the Oxyplot example files in the downloads section, all I see when I run the code is a plain graph. How do I graph data from my multidimensional array into the Scatter and HeatMap graphs? The code bellow is what I'm currently dealing with in regards to Oxyplot. Thanks ahead for you help.
// [Example("ScatterSeries with random MarkerSize (n=1000)")]
var plotModel1 = new PlotModel();
plotModel1.Subtitle = "BinSize = 8";
plotModel1.Title = "ScatterSeries with random MarkerSize (n=1000)";
var linearAxis1 = new OxyPlot.Axes.LinearAxis();
linearAxis1.Position = OxyPlot.Axes.AxisPosition.Bottom;
plotModel1.Axes.Add(linearAxis1);
var linearAxis2 = new OxyPlot.Axes.LinearAxis();
plotModel1.Axes.Add(linearAxis2);
var scatterSeries1 = new OxyPlot.Series.ScatterSeries();
scatterSeries1.BinSize = 8;
scatterSeries1.MarkerStrokeThickness = 0;
scatterSeries1.Title = "Series 1";
plotModel1.Series.Add(scatterSeries1);
// return plotModel1;
plot1.Model = plotModel1;
Meyip wrote at 2013-04-04 16:34:
line annotation does not work with y-axis set to my own custom axis
chage wrote at 2013-06-13 18:41:
I create a custom axis (derived from Axis), and overrides below methods:
1) GetTickValues
2) IsValidValue
3) IsXyAxis
4) Transform
the custom axis appear to work well on the plot as axis Y (this axis has pan and zoom disabled always). However I later found out that when I add vertical line annotation, it will not show in the plot. Horizontal line annotation works well on the other hand.
Is there anything that is depending on axis-Y (my custom axis) when I add vertical line annotation?
chage wrote at 2013-06-14 20:36:
What would be the best way to handle legend overflow?
typingcat wrote at 2012-10-11 06:56:
Hello.
When there are many plots, and their name is long, and the size of OxyPlot is small, legend overflows. It is drawn outside of OxyPlot, which makes my program look defective.
What options do I have? Can I make it not overflow outside of OxyPlot?
objo wrote at 2012-10-12 07:40:
Can you put the legends below the plot?
I added the issue http://oxyplot.codeplex.com/workitem/10009
How to show a OxyPlot in a PictureBox controller in WindowsForms?
huangzhqin wrote at 2014-05-20 19:03:
Should the OxyPlot only been shown in Forms? (I used the OxyPlot.WindowsForms.)
Using line series as annotation
Gimly wrote at 2013-09-19 12:19:
I would like to use annotations in the same way as the scatter example with least square fit, but with a polynomial fit.
I thought that I could use the "Equation" of the LineAnnotation, but the equation is too complex to define as I'm doing a graph that does a 2D representation of a 3D graph.
Is there a way to define the LineAnnotation with points, as we would do for the LineSeries?
Is there another way I could do that?
A "hack" that I tought would be to simply create LineSeries for my fit, but then when I click on the line I get the value of the fit, which I don't want. Can we remove the popup that displays when we click on the line?
objo wrote at 2013-09-20 09:05:
Gimly wrote at 2013-09-20 11:19:
LineAnnotation lineAnnotation = new LineAnnotation()
{
Equation = (double x) => { return Math.Sin(x); },
Type = LineAnnotationType.EquationY
};
And it gives me a nice sinusoid, doesn't seem to be any issue with displaying curves and the like.
I'll give a try at creating a PolylineAnnotation, will give me an excuse to dive into the code as I will probably have reason to do some changes for my needs in the future :).
Otherwise, is there a way to remove the popup that gives the value when we click for some specific series?
Thanks for your answer!
objo wrote at 2013-09-20 11:27:
I think that feature should be removed from the LineAnnotation, and suggest to create a subclass FunctionAnnotation!
Service d'assistance aux clients par UserEcho