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

Polar Plot sector

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

mhedqvist1 wrote at 2014-06-13 13:19:

Hello,

I'm trying to create a polar plot in WPF from 270 degrees to 90, passing through 0.

However, I just can't get it right.
Using StartAngle=180 and EndAngle=0 combined with Minumum=-90 or 270 and Maximum=90 or 450 is as close as I can get. But then the Major/MinorSteps are offset to start at 270 and ends at 90.

Anyone that got a solution to this?

Thank you!

Common Width for Bar Series

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

jezza323 wrote at 2012-01-03 20:40:

This one is kind of hard to explain.

I have a single chart, with 3 series. 2x Bar Series and 1x Line Series all against the same category axis. 1 bar series is all positive values, and the other is all negative values. I would like to display the series similar to a "stacked" series, but without the values being added. I would like the 2 bars to share their width across the category axis, with one series above zero and the other below zero. Any ideas how I can do this?

Great control by the way! Love it


objo wrote at 2012-01-03 21:05:

I see what you mean. That is something we should support, let me think about how to do it. I am adding it to the issue tracker. I think it should be implemented as a stacked bar series where negative values are accumulated below the 'base line'.


jezza323 wrote at 2012-01-03 21:31:

If you can't think of a way to do it in the current code, I am happy to do the coding to support it and add it to the project for you. I was thinking of changing the IsStacked property to an enum called StackType containing the following values - None (default), Additive, Seperate. Then modify the rendering process to render appropriately (just an extra branch for bar calcuation inside the current "IsStacked == true" branch)


objo wrote at 2012-01-03 21:41:

Great if you would like to create a patch for this! Does stacking mixed negative and positive numbers make sense? I don't think it is neccessary to create the StackType enum, simply stack positive values above the 'baseline' and negative values below the 'baseline'. 

If you create a patch, please make test cases for both horizontally and vertically stacked series.


jezza323 wrote at 2012-01-03 21:54:

Yes I think you are right, it does look weird when you stack positives and negatives anyway (I tried). I will take a look at it tonight and see what I can do.


jezza323 wrote at 2012-01-04 13:26:

By test cases do you mean nunit tests? or examples?

I wasn't able to find any tests which tested rendering (I only have the OxyPlot.WPF solution open at the moment though). I have created examples though.

I have got the code working well enough for my use today. I will look more closely and do some more analysis of my changes tonight before submitting any patch


objo wrote at 2012-01-04 13:31:

good, I was meaning examples in the ExampleLibrary (then it is easy to test on all platforms). Great if you can include both a horizontal and vertical example!


jezza323 wrote at 2012-01-04 13:33:

Thanks objo

I will hopefully submit a patch for you to review tonight. I also have another issue I will raise in the tracker and have a little look at with line smoothing


jezza323 wrote at 2012-01-05 21:10:

I have now submitted a patch. Ive not submitted a patched to codeplex before so I was unsure about the format expected... I have just uploaded a zip file containing the changed files in their appropriate paths.


objo wrote at 2012-01-05 21:28:

Cool, I will have a look as soon as I get some time (I am a bit busy right now, hopefully early next week!)

If you use TortoiseSVN it should be very easy to create a patch, read the manual!


jezza323 wrote at 2012-01-06 14:17:

I have resubmitted as a svn patch. I forgot to click add on the Work Item this time though...


jezza323 wrote at 2012-02-09 19:00:

As a further to this. With this particular graph, I have created separate axis for the BarSeries and LineSeries in it. The axis for the BarSeries is on the left, the Axis for the line series is on the right. Due to the values in use, the 0 point of the axis do not match. How would I go about getting the 0 point of the 2 vertical linear axes to line up (without hard coding the axis range)?


objo wrote at 2012-02-20 22:14:

Sorry, 'synchronized' axes are currently not supported. I added it as issue 9945.

System.InvalidOperationException - OnKeyDown

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

krzysiek_jrd wrote at 2014-07-08 10:21:

Hi All,

I'm plotting real time data using OxyPlot, everything seems to be working great apart of the exception in 'PlotModel.ResetAllAxes' method. The exceptions occurs each time I press 'a' key when the focus is on the OxyPlot area.

Can you please advice how to fix this issue?
OxyPlot.dll!OxyPlot.PlotModel.ResetAllAxes() Line 1237  C#
 OxyPlot.dll!OxyPlot.PlotCommands.HandleReset(OxyPlot.IPlotView view) Line 235  C#
 OxyPlot.dll!OxyPlot.PlotCommands..cctor.AnonymousMethod__6(OxyPlot.IPlotView view, OxyPlot.IController controller, OxyPlot.OxyKeyEventArgs args) Line 44   C#
 OxyPlot.dll!OxyPlot.DelegatePlotCommand<OxyPlot.OxyKeyEventArgs>..ctor.AnonymousMethod__0(OxyPlot.IView v, OxyPlot.IController c, OxyPlot.OxyKeyEventArgs e) Line 47   C#
 OxyPlot.dll!OxyPlot.DelegateViewCommand<OxyPlot.OxyKeyEventArgs>.Execute(OxyPlot.IView view, OxyPlot.IController controller, OxyPlot.OxyInputEventArgs args) Line 76   C#
 OxyPlot.dll!OxyPlot.ControllerBase.HandleCommand(OxyPlot.IViewCommand command, OxyPlot.IView view, OxyPlot.OxyInputEventArgs args) Line 533    C#
 OxyPlot.dll!OxyPlot.ControllerBase.HandleKeyDown(OxyPlot.IView view, OxyPlot.OxyKeyEventArgs args) Line 348    C#
 OxyPlot.Wpf.dll!OxyPlot.Wpf.PlotView.OnKeyDown(System.Windows.Input.KeyEventArgs e) Line 588   C#
Many thanks,
Krzysztof

objo wrote at 2014-07-10 13:15:

The 'a' command seems to work in the examples. Can you provide more information how to reproduce this?

wbidus wrote at 2014-07-14 10:03:

In my case this error occurs only after moving the chart. when i press 'a' key just after plot loads, nothing happens. When I move the plot and press 'a', exception appears.


An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

Additional information: Collection was modified; enumeration operation may not execute.

Edit. I am using oxyplot on WPF.

Slxe wrote at 2014-07-14 16:27:

Yea I've gotten that error a few times myself, but it generally cleans itself up. That's happening because you're moving or altering OxyPlots display, which is somewhat based on the data in each series points list, at the same time that data is being added to those points lists. I found it all depends on how often you're refreshing the displayed chart (calling InvalidatePlot(true)), in playing with it myself, in WinForms though, I've found generally anything under about 200ms starts getting pretty buggy because of these conflicts. Also keep in mind that that includes when you add data to the points lists, as zooming and panning calls InvalidatePlot(false).

Mouse interact doesn't work with HitTest

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

sharethl wrote at 2012-07-13 14:41:

I created a new class inherit from Rectangle, and override HitTest in order to know user click which point of a rectangle, however, if I override HitTest, the mouse event can not fire at all.

Once the HitTest is deleted, Mouse event can be fired.

How to solve this problem?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OxyPlot.Extended.Annotations {
    public class RectangleAnnotationMovable2:RectangleAnnotation {
        private DataPoint lastPoint = DataPoint.Undefined;
        private OxyRect screenRectangle;
        private int handleNumber;
        private OxyColor originalStroke;
        private double originalStrokeThickness;
        private OxyColor originalFill;

        protected override void OnMouseDown(object sender, OxyMouseEventArgs e) {
            if ( this.PlotModel == null)
                return;
            handleNumber = (int)e.HitTestResult.Index;
            lastPoint = this.InverseTransform(e.Position);
            originalFill = this.Fill;

            this.Fill = OxyColors.Red;
            this.PlotModel.InvalidatePlot(false);
            e.Handled = true;
        }

        protected override void OnMouseMove(object sender, OxyMouseEventArgs e) {
            if (this.PlotModel == null)
                return;
            var thisPoint = this.InverseTransform(e.Position);
            double dx = thisPoint.X - lastPoint.X;
            double dy = thisPoint.Y - lastPoint.Y;
            switch (handleNumber) {
                case 1:
                    this.MinimumX += dx;
                    this.MaximumY += dy;
                    break;
                case 2:
                    this.MaximumY += dy;
                    break;
                case 3:
                    this.MaximumX += dx;
                    this.MaximumY += dy;
                    break;
                case 4:
                    this.MaximumY += dy;
                    break;
                case 5:
                    this.MaximumX += dx;
                    this.MinimumY += dy;
                    break;
                case 6:
                    this.MinimumY += dy;
                    break;
                case 7:
                    this.MinimumX += dx;
                    this.MinimumY += dy;
                    break;
                case 8:
                    this.MinimumX += dx;
                    break;
            }
            lastPoint = thisPoint;
            this.PlotModel.InvalidatePlot(false);
            e.Handled = true;
        }
        protected override void OnMouseUp(object sender, OxyMouseEventArgs e) {
            if (this.PlotModel == null)
                return;
            this.Fill = originalFill;

        }
        /// <summary>
        /// Tests if the plot element is hit by the specified point.
        /// </summary>
        /// <param name="point">
        /// The point. 
        /// </param>
        /// <param name="tolerance">
        /// The tolerance. 
        /// </param>
        /// <returns>
        /// A hit test result. 
        /// </returns>
        protected  override HitTestResult HitTest(ScreenPoint point, double tolerance) {
            if (screenRectangle.Contains(point)) {
                return new HitTestResult(point);
            }

            return null;
        }

      
    }
}


objo wrote at 2012-08-09 00:39:

Thanks for reporting this, I added it as a bug http://oxyplot.codeplex.com/workitem/9977, will look into it later!

0

DrawImage method of PortableDocument class creates empty file

Dnyaneshwar Wadghane fa 9 anys 0
I am creating PortableDocumentImage image using byte array from png file, However the pdf document created is empty yet the size of the document is close to the size of the image i am trying to draw.

Tracker

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

DonkeyDan wrote at 2012-05-30 18:54:

Please be gentle as I am quite new to Oxyplot and am strugling with the lack of documentation.  I've got a couple of Tracker questions:

1st - is it possible to constanly show the Tracker?  I have found the methods for Show and Hide, but I don't want it to keep getting hidden when a mouse button is released.

2nd - is it possible to get and set the position of the tracker from outside the control?

3rd - Which is the best event to register to which fires when someone changes the tracker position on the graph?

 

Many thanks!


objo wrote at 2012-05-30 23:12:

1: Currently it is not. We can add a property that will not hide the tracker when the mouse button is released (but when I implemented it, I did not wish this behaviour). The code that hides the tracker is in the TrackerManipulator class.

2: You can get the mouse position, then transform to data coordinates (use axes/PlotModel methods)

3: It should be possible to subscribe to the MouseMove/PreviewMouseMove of the Plot control (I have not tested). The tracker control and tracker maniplautor are currently not raising any events.


Tech_Junkie wrote at 2012-07-19 11:10:

I "solved" the third point by adding mousehandlers to the PlotModel like this:

Constructor:
        PlotModel.MouseDown += Mouse_Down;
} 

private void Mouse_Down(object sender, OxyMouseEventArgs e)
        {
            if (e.ChangedButton == OxyMouseButton.Left)
            {
                <... do stuff>

                e.Handled = true; // all handled, do not set if other handlers need to do something
            }
        }

Similar handlers can be written for the MouseUp and MouseMove. Combining those should make it possible to know when the tracker should also be moved.


CJayant wrote at 2013-04-03 10:55:

Visual Studio is giving error Error
No overload for 'plot_Mousedown' matches delegate 'System.Windows.Forms.MouseEventHandler'

aapov wrote at 2014-01-08 19:37:

1st - is it possible to constanly show the Tracker? I have found the methods for Show and Hide, but I don't want it to keep getting hidden when a mouse button is released.
I've got the same need.
1: Currently it is not. We can add a property that will not hide the tracker when the mouse button is released (but when I implemented it, I did not wish this behaviour). The code that hides the tracker is in the TrackerManipulator class.
Is this property implemented? I can easily fork the this feature into code, but in long time it would be better if I could use the official versions.

Smart Labels/Annotations

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

smokingfish wrote at 2013-11-10 15:13:

Hello there,

first, great work - it is by far the easiest and most robust plotting library i came across yet.

I have a case where i want to display a lot of additional information about a data point.
I can put the detailed information in a custom tracker, that works great.

But i also want a summary of additional information right by the data point.
Annotation or even labels work great for that too.

Only limitation i found was when the plot is zoomed out and the annotations or labels overlap.

Is there some kind of smart annotation/label behavior planned?
Im thinking about auto hiding/collapsing overlapping annotations, so they become completely visible only when you zoom in.

Or even smart positioning for Arrow annotations, only the EndPoint is set and it looks for a non overlapping StartPoint by itself using some basic parameters (min distance, max distance etc.).

objo wrote at 2013-11-11 19:39:

It is not planned, but that's a good idea. And making it smart will probably be a bit challenging :) Can you add a spec of a the new feature in the Issues?
I think it should be implemented as new annotation types, to keep the original ones "simple and stupid".

smokingfish wrote at 2013-11-11 20:43:

Hello objo,

thanks for reply!
A new annotation type would be great too. I'm already playing around with some algorithms I found so far, I will try to contribute to that.
But yes, it is really challenging - there are whole papers about it.

Here are some useful information I found about the topic:
Force based Label placement sample in JS from the D3 project
Label placement on scatter charts
2006 Microsoft Patent for label placement, pretty useless but i guess that is what is used in MS Chart
Very nice dissertation from 1999
Nice paper about different algorithms

The term "smart" came from the MS Chart control, which I used for a customer in a WinForms application till now.
There you have "smart labels" which do mostly what i described and I think can be a good basis to look at for useful features.

If I cant do it myself I will add it in the Issues later.

Anyone working on OxyPlot for GTk# or MonoMac?

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

dsyme wrote at 2013-10-25 14:19:

Hi all,

Is anyone working on an OxyPlot backend for GTk#, or for MonoMac?

People in the F# community are looking for cross-platform charting solutions for basic data visualization purposes in data science programming, and OxyPlot looks like a good candidate for native charting (as opposed to HTML5 charting).

Thanks
Don

objo wrote at 2013-10-25 22:50:

It would be very interesting to see an implementations for OS X!

moljac is working on a Xamarin component - it would be great to see a Xamarin.Mac version in there too!
https://oxyplot.codeplex.com/SourceControl/network/forks/moljac/OxyPlotXamarinComponent

evolvedmicrobe wrote at 2013-11-02 05:10:

Objo, the altsoft guys who just ported Oxyplot (http://www.altsoftlab.com/) make mention of QT and GTK on their website, do you know if this implies it would be easy to use GTK# as a native charting option?

Alternatively, I have been playing around a lot with R.NET. The grid package in R contains all the primitives needed for IRenderContext (excepting some things like ellipses which could be manually done). Most importantly, they implement a textsizemeasurement technique, which for some reason seems hard to find in many places (are you still hoping to remove this though?).

I am writing a wrapper around the R grid package in .NET right now. One advantage of this is if we had Oxyplot to R-Grid Package, we would instantly get access to all the devices in the R "grDevices" package, namely PDF, EPS, PNG, BMP, X11, Screens, etc. etc. This would allow for PDF output on mac and linux to. Not sure if the R dependency would preclude inclusion in the main trunk or if the GTK option is already implied by altsoft, but would be curious to know.

Cheers,
N

objo wrote at 2013-11-03 09:14:

I have only tested the Silverlight version of the altsoftlab port, and the implementation of the IRenderContext seems to be 100%! I don't know how to use it with QT or GTK.

Do you mean http://rdotnet.codeplex.com/ ? I did not see grDevices there.

I am planning to add simple pdf export capabilities into the core library, this will make it available on all platforms and produce identical output everywhere. Hopefully I can submit the code soon!

evolvedmicrobe wrote at 2013-11-03 18:21:

I just tried to get oxyplot working on my mac through altsketch GTK Image.

On the positive side, the plot appears! However, the program gave me a SIGSEV right after taking that screen shot, so I don't know whether or not to call that a proof of principal. The altsketch code also looks a bit hairy and undocumented, so I am not sure how easy it would be to turn it into a native plot utility for F# purposes. Will take a bit of a longer look at it if I can find the time later.

Yep, I did mean http://rdotnet.codeplex.com/ . The grDevices is a library that comes by default with an R installation and handles all the different output devices that can be rendered to. (The figure at the very start of 1.2 in this book probably explains it best: http://www.e-reading.biz/bookreader.php/137370/C486x_C06.pdf )

Simple cross platform PDF export would be AWESOME. Will definitely look forward to seeing that soon!

All the best,
Nigel

dsyme wrote at 2013-11-03 18:24:

I have been looking at this today, going directly to the Mono GTk bindings. I have some most things working, but will need help from a GTk expert for some things. Working on the ExampleBrowser now.

Will share in a few days I hope.

dsyme wrote at 2013-11-04 19:25:

Here's a first cut at a Gtk# backend: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp/changeset/5f2a17d02561. it uses Mono.Cairo to do the drawing. There are still some TODOs, but all the plots in the ExampleBrowser basically seem to work on both Mac and Windows (using the same portable executable). Caveats
  • Events aren't being processed correctly. I'll look into that.
  • The ExampleBrowser tree control doesn't display correctly on Mac for some reason, but that's not a problem with the oxyplot backend. Also to run Gtk# applications on Mac you have to set an environment variable, see http://stackoverflow.com/questions/13885454/mono-on-osx-couldnt-find-gtksharpglue-2-dll.
  • I haven't tried on Linux X11 or other Gtk# display surfaces.
  • There are a number of TODOs where things were being done in the WindowsForms code which I couldn't map across to Cairo. If anyone knows GtkSharp and can offer advice that would be appreciated.

dsyme wrote at 2013-11-04 19:33:

Example plot using OxyPlot.GtkSharp:

Image

objo wrote at 2013-11-04 19:41:

This is very cool, I'll check it out!

dsyme wrote at 2013-11-05 12:34:

Event handling has been fixed here: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp/changeset/d9705ea6c345

Here are the possible TODOs (I don't think any are blocking, though it would be very nice to fix the first, and the others would likely improve the beauty of the plots)
  • Fix the example browser so the TreeView works on Mac
  • Configure smoothing mode in GTk#. The equivalent of this GDI:
        g.SmoothingMode = aliased ? SmoothingMode.None : SmoothingMode.HighQuality; // TODO: Smoothing modes
    
  • Get the DpiX and DpiY values for an image using GDK:
        return image == null ? null : new OxyImageInfo { Width = image.Width, Height = image.Height, __DpiX = 96, DpiY = 96__ }; // TODO DpiX, DpiY
    
  • In DrawImage, the srcX and srcY are being ignored. It doesn't seem to matter though
  • In DrawImage, the opacity is being ignored.
  • In DrawImage, the interpolate is being ignored.
            // g.InterpolationMode = interpolate ? InterpolationMode.HighQualityBicubic : InterpolationMode.NearestNeighbor;
    
  • Is this the right anti-aliasing setting? Other options are "Default", "Grey" and "None"
        g.Antialias = Antialias.Subpixel; // TODO  .TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
    
    

objo wrote at 2013-11-05 13:33:

Great! I could not get the ExampleBrowser to run (Windows 8.1) yesterday, will try to reinstall XamarinStudio and GTK#.
DpiX and DpiY are no more needed in the render context. Sync with the latest version and remove the GetImageInfo method.

dsyme wrote at 2013-11-05 15:38:

I've just
  • updated to head
  • built and run on OSX (all working ok now)
  • built and run on Windows 7 (all ok)
Haven't tried on Windows 8.1

dsyme wrote at 2013-11-05 16:34:

For those interested, here is a script which shows an example of using OxyPlot.GtkSharp.dll from F# Interactive on OSX.
#r "../gtk-sharp-2.0/gtk-sharp.dll"
#r "../gtk-sharp-2.0/gdk-sharp.dll"
#r "../gtk-sharp-2.0/atk-sharp.dll"
#r "../gtk-sharp-2.0/glib-sharp.dll"
        
open System;
open Gtk;

Application.Init();

fsi.EventLoop <- 
 { new Microsoft.FSharp.Compiler.Interactive.IEventLoop with
   member x.Run() = Application.Run() |> ignore; false
   member x.Invoke f = 
     let res = ref None
     let evt = new System.Threading.AutoResetEvent(false)
     Application.Invoke(new System.EventHandler(fun _ _ ->
       res := Some(f())
       evt.Set() |> ignore ))
     evt.WaitOne() |> ignore
     res.Value.Value 
   member x.ScheduleRestart() = () }
   
#r @"/Users/Don/codeplex/gtksharp/Source/OxyPlot.GtkSharp/bin/Debug/OxyPlot.dll"
#r @"/Users/Don/codeplex/gtksharp/Source/OxyPlot.GtkSharp/bin/Debug/OxyPlot.GtkSharp.dll"

module ExampleChart = 
    open OxyPlot   
    open OxyPlot.Series   

    let pm = new PlotModel("Trigonometric functions", "Example using the FunctionSeries", PlotType=PlotType.Cartesian,Background=OxyColors.White)

    pm.Series.Add(new FunctionSeries(Math.Sin, -10.0, 10.0, 0.1, "sin(x)",Color = OxyColors.Black))
    pm.Series.Add(new FunctionSeries(Math.Cos, -10.0, 10.0, 0.1, "cos(x)",Color = OxyColors.Green))
    pm.Series.Add(new FunctionSeries((fun t -> 5.0 * cos t), (fun t -> 5.0 * sin t), 0.0, 2.0 * Math.PI, 0.1, "cos(t),sin(t)", Color = OxyColors.Yellow))
    let plot = new OxyPlot.GtkSharp.Plot(Model = pm )
    plot.SetSizeRequest(400, 400)
    plot.Visible <- true

    let win = new Window("Hello")
    win.SetSizeRequest(600, 600)
    win.Add(plot)
    win.Show()

dsyme wrote at 2013-11-05 16:54:

@objo - can you check tthat I did the merge of the latest oxyplot code correctly? When I try to prepare a pull request it is showing many more diffs than I expected.

The branch I'm trying to send the PR from is here: https://oxyplot.codeplex.com/SourceControl/network/forks/dsyme/gtksharp?branch=default

I did something like this:
hg pull https://hg.codeplex.com/oxyplot
hg merge
hg commit
hg push
Did I forget something? I'm new to Mercurial.

thanks

objo wrote at 2013-11-05 20:20:

It looks good! I pulled it into the main branch!
I also added an OxyPlot.GtkSharp solution and applied StyleCop code cleanup to the new files.

dsyme wrote at 2013-11-05 21:52:

Great! Could you also add a nuget package for this? We want to use it in FSharp.Charting on OSX.

objo wrote at 2013-11-05 22:42:

I have built for .NET 4.0:
http://www.nuget.org/packages/OxyPlot.GtkSharp/
Can this assembly be used on OSX?

dsyme wrote at 2013-11-06 01:16:

Yes, it works just fine. See the sample here (this is using it from F# Interactive - called fsharpi on OSX)

https://gist.github.com/dsyme/7327184

dsyme wrote at 2013-11-06 01:17:

There is also a discussion thread here in the the F# community: https://groups.google.com/forum/#!topic/fsharp-opensource/SlOS0-vyyKI

CandleStickSeries multiple colors

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

decipher wrote at 2013-10-07 06:21:

I am using WPF and have looked at all of the sample code as well as the example application and I cannot figure out a way to get green bars when the close is greater than the open and red bars when the close is less than the open.

I'm starting to think this functionality is not available at the individual point level (O, H, L C in this example). Is this the case?

Thank you.
decipher

objo wrote at 2013-10-07 17:51:

I added two new properties for the fill color: IncreasingFill and DecreasingFill

decipher wrote at 2013-10-08 08:12:

Thank you for adding this. I notice it works fine in the winform examples but I can't get it to work in my WPF code.
          // Create the plot model
            PlotModel pm = new PlotModel("Minute Data for " + cboDates.SelectedItem.ToString());// { LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };

            var timeSpanAxis1 = new TimeSpanAxis { Position = AxisPosition.Bottom, StringFormat = "hh:mm" };
            pm.Axes.Add(timeSpanAxis1);
            var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
            pm.Axes.Add(linearAxis1);
            var csSeries = new CandleStickSeries
            {
                CandleWidth = 1,
                IncreasingFill = OxyColors.DarkGreen,
                DecreasingFill = OxyColors.Red,
                DataFieldX = "QTime",
                DataFieldHigh = "H",
                DataFieldLow = "L",
                DataFieldOpen = "O",
                DataFieldClose = "C",
                TrackerFormatString = "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
                ItemsSource = lstMinRec
            };

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

The output should be the same on any platform!

Note that CandleWidth is in screen units - I think it you should use a larger number.
I have not tested with a TimeSpanAxis, there might be an issue there.
Can you include some data that we can use in an example?
I added a small example using a DateTimeAxis.

decipher wrote at 2013-10-08 18:08:

The CandleWidth was the problem. When I increased it the colors showed up. One thing I noticed is the colors appear to be reversed. For IncreasingFill I would expect green and for DecreasingFill I would expect red. Increasing would be classified as the close value of the bar being greater than the open value of the bar.
 List<MinuteRec> lst = new List<MinuteRec>
            {
                new MinuteRec { QTime = TimeSpan.Parse("06:31:00"), O = 1672.5000, H = 1673.5000, L = 1671.7500, C = 1672.7500 }, 
                new MinuteRec { QTime = TimeSpan.Parse("06:32:00"), O = 1672.5000, H = 1673.5000, L = 1672.5000, C = 1672.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:33:00"), O = 1672.5000, H = 1672.7500, L = 1670.7500, C = 1671.2500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:34:00"), O = 1671.2500, H = 1671.2500, L = 1670.2500, C = 1670.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:35:00"), O = 1670.7500, H = 1671.7500, L = 1670.5000, C = 1671.2500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:36:00"), O = 1671.0000, H = 1672.5000, L = 1671.0000, C = 1672.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:37:00"), O = 1672.5000, H = 1673.0000, L = 1672.0000, C = 1673.0000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:38:00"), O = 1672.7500, H = 1673.2500, L = 1672.5000, C = 1672.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:39:00"), O = 1672.5000, H = 1672.7500, L = 1671.2500, C = 1671.2500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:40:00"), O = 1671.2500, H = 1672.5000, L = 1671.0000, C = 1672.0000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:41:00"), O = 1672.2500, H = 1672.5000, L = 1671.2500, C = 1672.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:42:00"), O = 1672.2500, H = 1672.5000, L = 1671.5000, C = 1671.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:43:00"), O = 1671.5000, H = 1671.7500, L = 1670.5000, C = 1671.0000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:44:00"), O = 1670.7500, H = 1671.7500, L = 1670.7500, C = 1671.7500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:45:00"), O = 1672.0000, H = 1672.2500, L = 1671.5000, C = 1671.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:46:00"), O = 1671.7500, H = 1671.7500, L = 1671.0000, C = 1671.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:47:00"), O = 1671.7500, H = 1672.2500, L = 1671.5000, C = 1671.7500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:48:00"), O = 1671.7500, H = 1672.7500, L = 1671.7500, C = 1672.5000 },
                new MinuteRec { QTime = TimeSpan.Parse("06:49:00"), O = 1672.2500, H = 1673.7500, L = 1672.2500, C = 1673.7500 },
                new MinuteRec { QTime = TimeSpan.Parse("06:50:00"), O = 1673.7500, H = 1675.0000, L = 1673.5000, C = 1675.0000 }
                    
            };

            // Create the plot model
            PlotModel pm = new PlotModel("Minute Data");

            var timeSpanAxis1 = new TimeSpanAxis { Position = AxisPosition.Bottom, StringFormat = "hh:mm" };
            pm.Axes.Add(timeSpanAxis1);
            var linearAxis1 = new LinearAxis { Position = AxisPosition.Left };
            pm.Axes.Add(linearAxis1);
            var csSeries = new CandleStickSeries
            {
                CandleWidth = 5,
                Color = OxyColors.DarkGray,
                IncreasingFill = OxyColors.DarkGreen,
                DecreasingFill = OxyColors.Red,
                DataFieldX = "QTime",
                DataFieldHigh = "H",
                DataFieldLow = "L",
                DataFieldOpen = "O",
                DataFieldClose = "C",
                TrackerFormatString = "High: {2:0.00}\nLow: {3:0.00}\nOpen: {4:0.00}\nClose: {5:0.00}",
                ItemsSource = lst
            };
            pm.Series.Add(csSeries);
Image

barns wrote at 2013-11-07 13:21:

These should be present on the HighLowSeries too.

Also, some people have different meanings of increasing and decreasing. Some compare close values of two candles instead the open and close. It will be nice to be able to determine the color by a custom calculation. Another more customizable approach is to have a separate series that determines the color of each candle/OHLC.

Any suggestions how to achieve this?

EDIT: A fine example of what I mean:

http://support.stockcharts.com/entries/20591-What-does-a-solid-black-or-hollow-red-candlestick-mean-

My thoughts on this are to add another series specific to this data. Then have an axis that support colors for a specific value. Much like scatter plot with colored axes but for candlesticks and HighLowSeries

StairStepSeries NullReferenceException

Oystein Bjorke fa 10 anys 0
This discussion was imported from CodePlex

csabi wrote at 2013-10-08 13:02:

If I use StairStepSeries without points and I click to the Plot, then I get a NullReferenceException.
If I use LineSeries, everything is OK. I think this code should be repaired:
            // snap to the nearest point
            var result = this.GetNearestPointInternal(this.Points, point);
            if (!interpolate && result.Position.DistanceToSquared(point) < minimumDistanceSquared)
            {
                return result;
            }
Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at OxyPlot.Series.StairStepSeries.GetNearestPoint(ScreenPoint point, Boolean interpolate) in c:\TeamCity\buildAgent\work\f48330714bade418\Source\OxyPlot\Series\StairStepSeries.cs:line 122
   at OxyPlot.Series.Series.HitTest(ScreenPoint point, Double tolerance) in c:\TeamCity\buildAgent\work\f48330714bade418\Source\OxyPlot\Series\Series.cs:line 122
   at OxyPlot.PlotModel.HandleMouseDown(Object sender, OxyMouseEventArgs e) in c:\TeamCity\buildAgent\work\f48330714bade418\Source\OxyPlot\PlotModel\PlotModel.MouseEvents.cs:line 82
   at OxyPlot.Wpf.Plot.OnMouseDown(MouseButtonEventArgs e) in c:\TeamCity\buildAgent\work\f48330714bade418\Source\OxyPlot.Wpf\Plot.cs:line 924
   at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at XamlGeneratedNamespace.GeneratedApplication.Main() in c:\xxxx\obj\Debug\App.g.cs:line 0
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

objo wrote at 2013-10-08 14:22:

thanks, fixed!