Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change default x-axis title in oxyplot?

Tags:

mvvm

wpf

oxyplot

I use oxyplot framework in wpf with MVVM pattern. And I want to change x-axis title, but I can not find any axis object. Axes property in PlotModel is empty. I find DefaultXaxis Property, and also it is null. How can I change default axis title without adding new Axes.

Thanks in Advance.

like image 908
Doctor Avatar asked Nov 10 '22 16:11

Doctor


1 Answers

Take what I say with a bit of salt, but it might help anyone reading this.

It seems that the DefaultXaxis property is null only until everything has been initialized and bound, etc. This doesn't happen in say, the WPF's Window's cs-file's Partial Class constructor. But it seems to be assigned a value after the binding to PlotView happens.

If your goal is purely to add a title to DefaultXaxis property, I guess you can do it after the binding of the PlotModel to the PlotView. (At least I presume that's the event; in my case, a user control event method seems to be able to get a non-null value for DefaultAxis)objectOfClassThatCreatedPlotModel.plotModelObject.DefaultXAxis.Title = "test";

But if anyone's after just adding an X-Axis title immediately after creating an instance of the PlotModel (I am not sure why OP wants to avoid this), just use something like:

plotModelObject.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = "x-title" })
like image 176
mehfoos yacoob Avatar answered Dec 24 '22 22:12

mehfoos yacoob