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

Strange error

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

Gala wrote at 2014-06-06 16:17:

Hi! Thank you for oxyPlot, it's really amazing))
Im working with real time data and sometimes get strange error:
System.NullReferenceException: in OxyPlot.Annotations.Annotation.Transform(DataPoint p) в c:\TeamCity\buildAgent\work\3b9fcf1ba397d0ed\Source\OxyPlot\Annotations\Annotation.cs: 115
I'm using arrow anotations and check everything before adding it to the plot view.

objo wrote at 2014-06-06 20:51:

This looks like a problem with the x-axis.
Are you adding the arrow annotation to a plot without axes/series? What platform are you on? Can you add some code that reproduces the error?

Gala wrote at 2014-06-06 21:21:

I'm using wpf. There are dateTime and value axeses in my model (dateTimeAxis as x-axis), and there are couple line series too) Here is the code the annotation adding:
   var arrow = new ArrowAnnotation();
   arrow .Text = info;
   arrow .StartPoint =  new DataPoint(DateTimeAxis.ToDouble(currentTime), value- value/ 100000);
   arrow .EndPoint =  new DataPoint(DateTimeAxis.ToDouble(currentTime),value);
   PlotModel.Annotations.Add(tradeToDisplay);
Thanks)

objo wrote at 2014-06-06 21:51:

Can this be a race condition? Can you try locking the PlotModel.SyncRoot when changing the model?

Gala wrote at 2014-06-09 17:28:

Thank you! It solve my problem.

Change labels of LinearAxis

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

Nirraven wrote at 2013-10-02 11:58:

Hello,

I'd like to display DateTime/double values in a non-DateTime x-axis manner.
The x-axis' labels are still to be DateTimes, but with a regular distance instead of being converted to doubles.

Maybe it's more clear with this (Excel chart) pic showing the upper chart as DateTime x-axis, the lower chart as I'd like to have it displayed:
http://s8.postimg.org/fm7gx3c39/Date_Text_Axis.png

Can I achieve this with oxyplot without altering any code?

Thanks in advance!
Nirraven

objo wrote at 2013-10-02 12:25:

Can CategoryAxis be used?

Nirraven wrote at 2013-10-02 13:58:

Requires a little more coding to prepare the data, but works perfectly.

Thanks a lot and keep up the great work!

Bar Histogram Charts

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

jpnavarini wrote at 2012-03-20 21:34:

I would like to create a bar chart, in order to estimate a Histogram. I don't need to plot the fitted histogram, only the bars, as shown on the following figure from WikiPedia: http://en.wikipedia.org/wiki/File:Black_cherry_tree_histogram.svg

I would like to have bar a chart in a linear vs. linear axes configuration. Then I would have in the bottom axis the values and in the left axis the frequency of occurence of the values in the interval defined by the bar basis.

Is is posible to do this kind of plot with OxyPlot? How it can be done?


objo wrote at 2012-03-30 13:32:

The BarSeries requires a CategoryAxis.

Try the RectangleBarSeries which should support linear axes, but this means you have to set the minimum and maximum X/Y of each rectangle (bar).

[Suggestion] OnTrackedItemChanged in PlotModel

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

ishlasko wrote at 2013-08-22 18:27:

Currently, there's no straightforward way to determine what item is currently being displayed in the tracker. It'd be pretty simple to add a virtual OnTrackedItemChanged method to the PlotModel class, then have the TrackerManipulator trigger it in the Delta and Completed methods.

That way, anyone subclassing the PlotModel could override that, and set properties that could be bound to in other parts of the GUI.

Added this myself locally, but I think others might find it useful if it was in the official build.

(By the way... Big fan of OxyPlot... Been using it professionally for a couple years now... Great library!)

objo wrote at 2013-08-22 21:04:

Good idea! I added a TrackerChanged event on the PlotModel. It also works on windows forms where the tracker is not yet implemented... :)

ishlasko wrote at 2013-08-23 14:52:

Just tried it out in the latest build... Works perfectly, thanks :)

ishlasko wrote at 2013-09-05 23:15:

Found a minor glitch. When you start filtering out items via the IsValidPoint override, the new event starts returning the wrong index/item. Easy fix, though. In XYAxisSeries.GetNearestPointInternal, add an "i++" before the "continue"

objo wrote at 2013-09-06 06:47:

thanks! fixed

Save and read plot

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

sharethl wrote at 2012-08-19 02:40:

Hi

Could any one tell me what is the best way to save plot? including annotations and series.

One way I saw an example is :

create Property class for each annotation, then serialize a collection of property classes.

when read the saved file, base on property classes to create plot with annotations. 


objo wrote at 2012-08-21 13:04:

It should be possible to serialize the PlotModel, but I am not sure if I would recommend it... The data structure may change... I think the client application should be responsible for this, using its own model. I'm interested in hearing other opinions on this!


sharethl wrote at 2012-08-21 16:06:

I did test to serialize PlotModel, 

Some properties could not be serialized, like Plot, OxyThichness(need add serialized attribute.)

So will user property class to make a copy of annotation and save them. easier.

 

Thanks


objo wrote at 2012-08-23 15:53:

I added http://oxyplot.codeplex.com/workitem/9986, it should not be difficult to fix this!

MouseDown issue with smooth curve

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

endorphing wrote at 2013-01-25 18:51:

I noticed that in the MouseDown example, if I enable curve smoothing, I can add new points but get an exception when trying to move a points around. I think the problem is with the e.HitTestResult.Index not being returned correctly (comments below). Is there an alternate way to get the index of the nearest point?

 

// Add a line series
            var s1 = new LineSeries("LineSeries1")
            {
                Color = OxyColors.SkyBlue,
                MarkerType = MarkerType.Circle,
                MarkerSize = 6,
                MarkerStroke = OxyColors.White,
                MarkerFill = OxyColors.SkyBlue,
                MarkerStrokeThickness = 1.5,
                Smooth = true //enable smoothing
            };
            s1.Points.Add(new DataPoint(0, 10));
            s1.Points.Add(new DataPoint(10, 40));
            s1.Points.Add(new DataPoint(40, 20));
            s1.Points.Add(new DataPoint(60, 30));
            model.Series.Add(s1);

            int indexOfPointToMove = -1;

            // Subscribe to the mouse down event on the line series
            s1.MouseDown += (s, e) =>
            {
                // only handle the left mouse button (right button can still be used to pan)
                if (e.ChangedButton == OxyMouseButton.Left)
                {
                    int indexOfNearestPoint = (int)Math.Round(e.HitTestResult.Index);
                    //indexOfNearestPoint: 297, Exception: Index was out of range. Must be non-negative and less than the size of the collection.
                    var nearestPoint = s1.Transform(s1.Points[indexOfNearestPoint]); 

 

 


objo wrote at 2013-02-10 23:31:

Yes, you get an index to the smoothed point collection.
I think the CanonicalSplineHelper must be extended to get the index in the original point collection. Or do you have other good ideas?

Invalid Special Characters in Unit description

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

jpnavarini wrote at 2012-04-19 19:20:

I have some measurements in my database which are angles, measured in degrees. The unit is º, just as temperatures in degrees Celsius (ºC). However, it is not possible to represent the º character in the legend. When I add the unit as º, it is replaced by a question mark in the legend.

 

Is it possible to make OxyPlot understand and represent º?

Thanks!


objo wrote at 2012-04-19 21:56:

Are you using the right degree symbol (Alt+0176)? UTF-8? Is the symbol included in the font you are using? Are you using WPF, SL or WinForms?

I'll change the ExampleLibrary/AxisExamples/TitleWithUnit example to demonstrate "°C" as the unit - it works fine here.  

Panning error in Log axis with Absolute Min/Max

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

ryoujr wrote at 2013-06-17 20:11:

Dears,

I found one issue when it applies Log axis with Absolute Min/Max values, Panning should be blocked with those absolute values, but when I tried the panning, the chart showed wrong range of values and graph was disappeared.

I think I found the cause of this as below, but I'm not sure how I can apply this modification on you main source tree, so, after reviewing this I would appreciate it if you could apply this change on your main release.

in "LogarithmicAxis.cs"
    public override void Pan(ScreenPoint ppt, ScreenPoint cpt)
    {
       ...
        if (newMaximum > this.AbsoluteMaximum)
        {
            newMaximum = this.AbsoluteMaximum;
            //Original Code
            // newMinimum = newMaximum * this.ActualMaximum / this.ActualMinimum;

            // New Fix
            newMinimum = newMaximum / this.ActualMaximum / this.ActualMinimum;
        }
    }
Regards,
Ian Ryou.

objo wrote at 2013-06-18 12:22:

Thanks for reporting the bug!
I think the correct code should be
newMinimum = newMaximum * this.ActualMinimum / this.ActualMaximum;
I am submitting the updated source code now. I have also included an example model that can be tested in the example browser.

For future bug fixes:
  • create a fork
  • create an example/unit test that I can use to verify that the fix is working
  • submit a pull request

ryoujr wrote at 2013-06-18 18:30:

Hello Objo,

Thank you for your kind response.
Yes correct! After posting the issue, I applied my fix and found another issue and I found that the exact solution was the same as you suggested.

I hope you have a great day.

Regards,
Ian.



NuGet status for OxyPlot.Metro package?

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

cureos wrote at 2014-04-15 22:58:

Dear Oystein,

many many thanks for developing and sharing this terrific library!

I have planned to use it in my Windows Store application. However, I note that whereas the OxyPlot.Core library on NuGet is currently at version 2014.1.277.1 (from April 10), the OxyPlot.Metro library is still at version 2014.1.1.1 from January 7. Why is this? And what is the current status of the Metro library on CodePlex?

It seems like the latest Core library is not fully compatible with the latest Metro library; I get a "Method Not Found" exception when trying to plot a line series (unfortunately I do not have all the data for the crash right now, but I can bring it forward if you want me to).

Best regards,
Anders @ Cureos

objo wrote at 2014-04-16 07:44:

thanks for the notice! I will investigate this. We should also address this related issue: https://oxyplot.codeplex.com/workitem/10167

cureos wrote at 2014-04-16 22:46:

I just checked OxyPlot.Metro on NuGet, http://www.nuget.org/packages/OxyPlot.Metro/, and I see that a new version is now released in sync with the latest Core library! Great job, Oystein, many many thanks for taking care of this issue so quickly.

I will upgrade to the latest version as soon as possible and give it some serious testing :-)

Best regards,
Anders @ Cureos

objo wrote at 2014-04-16 23:20:

yes, the package is updated, but I have not had time to test it yet. I only noticed that the generic.xaml file is no more generated.
Let us know if it is working or not!

cureos wrote at 2014-04-17 07:12:

Hmm, there seem to be a few issues with OxyPlot.Metro 2014.1.283.1:
  • My Windows Store app is targeted at Windows 8(.0), and it could successfully use version 2014.1.1.1. When I update OxyPlot.Metro to the latest version, the NuGet manager does not complain. But when I build the project, I get a warning that the OxyPlot.Metro package was built with an incompatible version, and I also get a compilation error in the auto-generated file related to my XAML view, claiming that "the namespace OxyPlot could not be found". Ideally, this incompatibility should have spotted already by NuGet Manager, right?
  • After retargeting my Windows Store app to Windows 8.1, building succeeds, except that the method "Plot.RefreshPlot()" is no longer available. In principle, I guess this is a good sign (I assume the plot is meant to update automatically in the general case)? However, all I see is a white sheet covering the entire plot area. No axes, no curves, no nothing. I tried to replace the "RefreshPlot()" call with "InvalidatePlot()", but to no avail.
I realize that this is not much to build debugging on. If you want more detailed information, just let me know what you need and I'll try to provide it. But for the time being I feel that it is best for me to revert to version 2014.1.1.1 again.

Best regards,
Anders

objo wrote at 2014-04-25 11:44:

  1. Is it possible to build for Windows 8.0 in VS 2013? The "target platform version" selector seems to be disabled.
  2. RefreshPlot has been removed, use InvalidatePlot. The plot is not updating automatically, you need to use the invalidate method.

cureos wrote at 2014-04-25 11:56:

Thanks for the response!
  1. The project was originally created with VS 2012, and I have not yet performed the upgrade for this project. I am not sure, but I believe that MS intends to support Windows 8.0 for a while longer, even though they encourage users to upgrade. Would it be possible to "downgrade" OxyPlot.Metro to Windows 8.0, or is it relying on new functionality in 8.1?
  2. OK, good to know.
As soon as possible, I will give the latest NuGet release another try. I'll report my findings after having tested it.

Best regards,
Anders

objo wrote at 2014-04-25 22:07:

  1. No, it is not relying on any 8.1 functionality. The build machine only has VS 2013 installed and I am worried that it will be difficult to build for 8.0 there. If anyone really needs support for 8.0, please add a request in the issue tracker.

Copy chart to clipboard

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

jacobc1000 wrote at 2012-11-24 13:59:

Hi,

Thanks for a great project. It really works!

 

I am currently using it for a project that generates various barchart- and scatter charts. I'm using WPF and MVVM where the PlotModel is generated in the viewmodel each time the user changes criteria. The chart itself is hosted in <oxy:ploy> control.

I need to be able to copy the visual representation (i.e. the <oxy:plot> control) to the clipboard. Preferably as a vector image to insert into MS Office applications. I know that generating WMF/EMF files from WPF is challenging at best so a simple bitmap could also do.

What is the best way of accomplishing this? Thanks.


objo wrote at 2012-11-26 06:05:

Try Ctrl-C, the Plot control is bound to ApplicationCommands.Copy.

The Plot control also has SaveBitmap, ToBitmap, ToXaml,  methods.

Or use PngExporter, SvgExporter, PdfExporter etc.


Tephyrnex wrote at 2013-03-18 15:33:

I've searched all of the .NET 4 source and the only reference I find to Keys.C is in Plot.cs (WinForm) (OnPreviewKeyDown) and that section of code doesn't copy a BMP to the clipboard. If anyone can shed light, it would be much appreciated.