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

Custom draw axis labels

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

nicolasr75 wrote at 2013-09-10 22:20:

Hello all,

I really appreciate the possibility to have four y-axes using the PositionTier property (two axes on the left and two on the right)
My problem is that the user can not tell to which axis a specific series is bound.

Does anyone have experience how to solve this?

A friend suggested I should have small, colored squares behind the axis titles to indicate the associated series.
But this would require that I custom draw the axis titles? Any idea how to do this?

thanks in advance!
Nicolas

everytimer wrote at 2013-09-10 22:41:

I think the easiest solution is a variation of your friend's suggestion. But instead marking the axes, distinguish the series with different styles: you can choose from LineStyle (Solid, Dot, Dash, and combinations), LineThickness, Color, and Markers. You could also use the Title to indicate which axis owns the Series. To make things clearer for the user you should add a custom Legend with indications. Other solution could be to create two Lists of OxyColors with Red/Blue tones (for example). Then choose appropriate color for your axes. Good luck.

objo wrote at 2013-09-11 20:21:

@nicolasr75: interesting question!

It is possible to subclass the axis and override the rendering, but I see the HorizontalAndVerticalAxisRenderer need some refactoring to make it easier (the RenderAxisTitle method is not overridable).

@everytimer: good suggestion, note also that the color of the axis title can be set to match the series that use the axis

See also
https://oxyplot.codeplex.com/workitem/9192

nicolasr75 wrote at 2013-09-11 20:35:

Many thanks to you both!

@everytimer: very interesting ideas, I will think about them and do some tests with it...

@objo: so you say it is in principle possible to render the axis myself? Could you give me a hint which classes in which files implement the original rendering?
Maybe an intermediate solution would be to duplicate the code in my derived class. By the way: this is for maximally four vertical axes and currently only for WPF.

Nicolas

objo wrote at 2013-09-11 20:43:

Override the Render method. You see the current implementation in Axis.cs
Your derived class will work on all platforms.

nicolasr75 wrote at 2013-09-11 20:52:

Thanks for the quick reply (and of course for this awesome component!)
Nicolas

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

I submitted some changes that should make it easier to override the axis rendering classes. Note that these classes should be refactored later and then you may need to do some changes in your code (that's why I try to keep the public/protected API to a minimum...)

nicolasr75 wrote at 2013-09-12 00:04:

Thanks for the changes.

For a first try I have derived special implementations from LinearAxis and HorizontalAndVerticalRenderer.
I have overridden the Render methods and call the base classes methods. After that I call my rendering code for colored rectangles that represent the associated series. I had to use Reflection to get at some internal properties of the Axis class though.
This seems to work fine for now!

thanks again for your help!

Null reference error

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

BlindMonk wrote at 2013-09-04 12:49:

In polygonannotation (WPF) this throws error:
polygonAnnotation1.Points.Add(new OxyPlot.DataPoint(8,-4));
Full error:
System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=sepsi
  StackTrace:
       at sepsi.ArrToImage.arraytoImageCon(List`1 dataIn, Int32 wid, Int32 ht, Boolean isAmp) in E:\projects\nstest\nstest\MainWindow.xaml.cs:line 1611
       at sepsi.MeanData.listToImage(Int32 wid, Int32 ht) in E:\projects\nstest\nstest\MainWindow.xaml.cs:line 799
       at sepsi.MainWindow.processfocfile(GBSFile fObj) in E:\projects\nstest\nstest\MainWindow.xaml.cs:line 601
       at sepsi.MainWindow.<.ctor>b__2(Object o, EventArgs`1 args) in E:\projects\nstest\nstest\MainWindow.xaml.cs:line 84
       at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
       at sepsi.FileListWindow.Button_Click(Object sender, RoutedEventArgs e) in E:\projects\nstest\nstest\fileList.xaml.cs:line 74
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
       at System.Windows.Controls.Primitives.ButtonBase.OnClick()
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       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.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       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.InvokeImpl(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.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at sepsi.App.Main() in E:\projects\nstest\nstest\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
       at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
       at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
       at System.Activator.CreateInstance(ActivationContext activationContext)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

objo wrote at 2013-09-04 20:03:

Thanks, I have now initialized the Points property. It should be consistent with the Points property in DataPointSeries.

BlindMonk wrote at 2013-09-05 12:14:

thanks. worked!!
0

WPF and Oxyplot: graph with CategoryAxis and LogarithmicAxis

Georges il y a 9 ans mis à jour il y a 9 ans 1

Hello everyone,

I am currently playing with Oxyplot and the demo samples (that one can download there https://github.com/oxyplot/oxyplot/archive/develop.zip), more particulary the sample 'ColumnSeriesDemo'.
Here is what it loks like when executed:


Image 36


Code:
public MainWindow()
{
this.InitializeComponent();
// Create some data
this.Items = new Collection<Item>
{
new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19},
new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9},
new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29}
};
// Create the plot model
var tmp = new PlotModel { Title = "Column series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };
// Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis.
tmp.Axes.Add(new CategoryAxis { ItemsSource = this.Items, LabelField = "Label" });
tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });
// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
tmp.Series.Add(new ColumnSeries { Title = "2009", ItemsSource = this.Items, ValueField = "Value1" });
tmp.Series.Add(new ColumnSeries { Title = "2010", ItemsSource = this.Items, ValueField = "Value2" });
tmp.Series.Add(new ColumnSeries { Title = "2011", ItemsSource = this.Items, ValueField = "Value3" });
this.Model1 = tmp;
this.DataContext = this;
}
I would like to have a logarithmic Y axis.
In the code above, I change the second axis declaration from
tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });
To
tmp.Axes.Add(new LogarithmicAxis { MinorTickSize = 0, Minimum = 1, Maximum = 35, Title = "Log Axis", Position = AxisPosition.Left, Base = 10, TickStyle = TickStyle.Outside });
However, when executing the code, the result is as follow:

Image 35


What am I missing please?

PDFs on Mono

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

evolvedmicrobe wrote at 2013-07-17 17:50:

Hi,

I wanted to run by/suggest some ideas for getting oxyplot to work on mono.

Right now, the PDF generation fails in mono because PDFSharp uses the User32.dll file to get some binary information to embed in the PDF for the various fonts. Myself and others have tried to work around this by either 1) Embedding the font information ahead of time in the PDF assembly, or 2) Grabbing the information directly from the font files on the local machine in a platform specific way.

Unfortunately, it seems that the results are still not up to par... and the rendering is much better on windows. I think this might have to do with the GDI library in mono not behaving the same way as the windows one, but it's a pretty buried problem and I can't track it down.

I was thinking of investing more time in it, but it also seemed to me that perhaps just switching over to a different PDF generating library, such as iTextSharp, to do the rendering. It seems shapes are possible as in here:

http://www.mikesdotnetting.com/Article/88/iTextSharp-Drawing-shapes-and-Graphics


I wanted to ask if other people have attempted PDF rendering on Mono though, to see if they had any insights on the ease or feasibility of either:

1) Trying to switch to iTextSharp
2) Trying to get PDFSharp to render correctly.
3) Deciding the problem is too much work to invest in.

Does anyone have any thoughts or experience in how hard any of these might be? (hours/days??)

objo wrote at 2013-07-19 08:24:

Note that iText is licensed under AGPL. See the license terms.

I would like to see the following changes rather than spending time on iTextSharp and PDFSharp
  • change OxyPlot text rendering so text alignment does not depend on text measurements
  • include a small pdf exporter that can render lines, fill polygons and render text in the OxyPlot core library (PCL). I did some prototyping some time ago, and it seems feasible (but the text/font handling is probably the hardest part). See pdf reference

evolvedmicrobe wrote at 2013-07-25 17:22:

hmm, agreed it would probably be better to move away from iText or PDFSharp.

I wound up using a hacked version of pdfsharp described here: http://forum.pdfsharp.net/viewtopic.php?f=4&t=1206&p=7289#p7289 that works, provided one tells it where to find the fonts on the local system, which is something of a pain. I don't think embedding the fonts works either because mono uses X11 to do the drawing, and they may not match.

Looks like this is more than I can handle now though so will have to leave the issue for now. Thanks for the response though!

Draw a graphic from an equation

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

FrankiAA wrote at 2013-04-04 11:16:

Hi, i actually realize an app and i need to draw some equations like y = ax² + bx + c = 0 or
y = ax³ + bx² + cx + d = 0.
What's the best and the easiest way to do that?
i saw examples with cos, sin,... but it's not really what i'm look for i guess...
Thanks.

objo wrote at 2013-04-18 09:57:

Try to use a lambda function, something like:
new FunctionSeries( x => a*x*x*x + b*x*x + c*x + d, .... )

IsAxisVisible property not working when binding to Model

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

sargent wrote at 2014-06-16 04:26:

I'm using WPF and I have created my PlotModel in the ViewModel which I am binding to from XAML. However, when I do this the IsAxisVisible property does not function. The axis is always visible whether the property is set to true or false.

IsAxisVisible not working

<oxy:Plot Width="600" Height="200" Margin="0" Model="{Binding UserPlotModel}">
                            <oxy:Plot.Axes>
                                <oxy:DateTimeAxis Position="Bottom" 
                                                  StringFormat="hh:mm:ss" 
                                                  IsAxisVisible="false" 
                                                  Maximum="{Binding PlotTimeMax}" 
                                                  Minimum="{Binding PlotTimeMin}"/>
                                <oxy:LinearAxis Position="Left" IsAxisVisible="false"/>
                            </oxy:Plot.Axes>
                        </oxy:Plot>
In other plots where I am binding through the ItemSource the IsAxisVisible property works fine. It appears to be an isolated case when binding to Model. Am I doing something wrong or is there a work around for this?

IsAxisVisible Working

  <oxy:Plot Width="600" Height="200" Margin="0">
                            <oxy:Plot.Axes>
                                <oxy:DateTimeAxis Position="Bottom" StringFormat="hh:mm:ss"/>
                                <oxy:LinearAxis Position="Left" IsAxisVisible="True"/>
                            </oxy:Plot.Axes>
                            <oxy:LineSeries ItemsSource="{Binding PartsPerHourDataPoints}"/>
                        </oxy:Plot>

objo wrote at 2014-06-16 09:59:

The Model property should override all the properties and collections (annotations, axes, series) of the PlotView, so I think this is working as intended.
But I have created https://oxyplot.codeplex.com/workitem/10222, I think this should generate a runtime error (exception).
See also https://oxyplot.codeplex.com/workitem/10128

sargent wrote at 2014-06-19 03:57:

Is there a way to create a RectangleBarSeries without using the Model property? I've been experimenting but haven't found a way around this issue.

Copyright holder

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

objo wrote at 2014-02-16 14:43:

Currently the copyright holder in the license text shows the name of the coordinator.

When other collaborators contribute with large portions of code, it feels strange to list my name there. And I guess they also want to be released from liability.
I also want to encourage contributions, and it may be strange to create a major fature and put my name in the copyright text...

Should it be changed?

a. more generic text like "OxyPlot contributors"? then list contributors in a separate file?
b. list of all contributors on each file? it is more work to keep track of it, cannot replace by general header

stephenroe wrote at 2014-02-24 21:15:

Why not go for:

Copyright (c) 2014 OxyPlot.org

and then maintain a CONTRIBUTORS file located in the root of the project?

objo wrote at 2014-02-25 08:30:

Yes, a contributors file should be added, maybe also a AUTHORS file that lists the copyright holders?
like
http://golang.org/CONTRIBUTORS
http://golang.org/AUTHORS
http://golang.org/LICENSE

Another alternative: Copyright (c) 2014 The OxyPlot Authors.

Should there be a CLA?
http://en.wikipedia.org/wiki/Contributor_License_Agreement

objo wrote at 2014-02-25 20:41:

I see jQuery uses MIT license and has an AUTHORS.txt file
https://github.com/jquery/jquery

stephenroe wrote at 2014-02-25 23:33:

Yes, and it has a nice copyright phrase:

Copyright (c) 2014 jQuery foundation and other contributors

Going in this direction would allow you to keep your name as the major copyright holder. For example:

Copyright (c) 2014 Oystein Bjorke and other contributors

At the end of the day, due to source control, it is very easy to identify each authors contribution.
http://stackoverflow.com/questions/2228188/finding-the-author-of-a-line-of-code-in-mercurial

objo wrote at 2014-02-27 20:32:

I changed to Copyright (c) 2014 OxyPlot contributors and added AUTHORS and CONTRIBUTORS files. Will update the file headers in the source code soon.
The list in the CONTRIBUTORS file was compiled from the Hg history, but it is very possible some contributors are missing. Please send me a notification to be added to the CONTRIBUTORS or AUTHORS lists. Also let me know about other improvements. (CLA?)

I am currently reading "Producing OSS" by Karl Fogel and my goal is simply to get more collaborators on the project!

http://www2.econ.iastate.edu/tesfatsi/producingoss.karlfogel2005.pdf
http://www.amazon.com/Producing-Open-Source-Software-Successful/dp/0596007590
Écarté

Bug: In Annotations - No Clipping Demo

Oystein Bjorke il y a 10 ans mis à jour par anonymous il y a 10 ans 1
This discussion was imported from CodePlex

ckoo wrote at 2012-03-12 07:38:

When you drag the plot, half of the plot remains frozen, which leads to the situation where you can have two origins on the same plot. The plot area seems to be divided into 4 separate quadrants, each with their own behaviour.


objo wrote at 2012-03-12 07:48:

This is the desired behaviour. There are four axes in this plot, and we are testing that the annotation lines are extended across the whole plot area.


ckoo wrote at 2012-03-12 10:51:

OK. Looks very confusing at first. Thanks for the clarification.

Misbehaviour of the Heatmap series

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

geopars wrote at 2013-05-21 22:58:

Hi,
First of all a big bravo for the project. You have done an amazing job.
I experienced an interesting misbehavior of the heatmap series. When you are adding a symmetric matrix, the heatmap series generated is not completely correct since it is slightly shifted.

Image

Here is the code that I used to generate the above image.
public static PlotModel SymmetricHeatmap()
        {
            double x0 = 0;
            double x1 = 16;
            double y0 = 0;
            double y1 = 16;

            var random = new Random();
            var data   = new double[17,17];

            for (var i = 0; i < 17; i++)
            {
                data[i, i] = 0.0;
            }
           
            for (var i = 1; i < 17; i++)
            {
                for (var j = 0; j < i; j++)
                {
                    var num = random.NextDouble();
                    data[i, j] = num;
                    data[j, i] = num;
                }
            }
            
            var model = new PlotModel("Peaks");
            model.Axes.Add( new ColorAxis 
                                { 
                                    Position    = AxisPosition.Right, 
                                    Palette     = OxyPalettes.Hot(500), 
                                    HighColor   = OxyColors.Gray, 
                                    LowColor    = OxyColors.Black 
                                });

            model.Series.Add(new HeatMapSeries { X0 = x0, X1 = x1, Y0 = y0, Y1 = y1, Data = data });
            return model;
        }
Also I had to change the Render override of the HeatmapSeries in order to get the colors to align correctly according to the axis.
public override void Render(IRenderContext rc, PlotModel model)
        {
            if (this.Data == null)
            {
                this.image = null;
                return;
            }

            var left        = this.X0;
            var right      = this.X1;
            var bottom  = this.Y0;
            var top        = this.Y1;

            var s00 = this.Transform(left, bottom);
            var s11 = this.Transform(right, top);
            var rect = OxyRect.Create(s00, s11);

            if (this.image == null || this.Data.GetHashCode() != this.dataHash)
            {
                this.UpdateImage();
                this.dataHash = this.Data.GetHashCode();
            }

            if (this.image != null)
            {
                var clip = this.GetClippingRect();

                rc.DrawClippedImage(clip, this.image, rect.Left, rect.Top, rect.Width, rect.Height, 1, true);
            }
        }

x-axis in descending order

Oystein Bjorke il y a 10 ans 0
This discussion was imported from CodePlex

yt2 wrote at 2013-08-13 16:39:

Hi,

I'm using oxyplot for some scientific stuff with C# and WPF. I'm looking for a way to sort the x-axis in descending order (ex. 720 to 400).

I tried a lot of things and did a research on the web - but didn't find any way to solve this. Could you please help me?

Thanks
Nico

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

Did you took a look to the examples? See "Reversed" in Axis Examples.

You need to set the StartPosition and EndPosition of your axis to 1 and 0 respectively. Then if you want you can set the Minimum/Maximum. Good luck

yt2 wrote at 2013-08-14 10:35:

Thanks! I had a look at the example explorer but I wondered how to see the code behind - now I know.