Styling the plot

Jul 19, 2012 at 12:19 PM

I am busy implementing a lineseries with two axes to show an overview of frequencies and their intensity. And until now I've used the styling as I've copied it from an example, in the definition of a lineseries:

LineSeries ls = new LineSeries()
{
    Color = OxyColors.Green,
    StrokeThickness = 2,
    MarkerType = MarkerType.Square,
    MarkerSize = 3,
    MarkerStroke = OxyColors.Black,
    MarkerStrokeThickness = 1
};
I was wondering if (and how) I can take these styling elements out of the code and put it in a styling in a xaml ResourceDictionary? Is this possible?

Jul 20, 2012 at 8:38 AM

I seem to have already solved this by using a vertical LineAnnotation :)

Thank you for providing the functionality!

Jul 20, 2012 at 1:03 PM

An additional question though, is it possible to have a vertical line and a horizontal text-label with it? Or do I have to position a TextAnnotation myself? (which is tricky, because the scaling depends on zooming, and I want a constant distance between the line and the text)

Coordinator
Aug 8, 2012 at 10:56 PM

Yes, the line annotation should have a 'Text' property you could use.You have some control of the position/alignment - see the TextPosition, TextMargin, TextHorizontalAlignment and TextVerticalAlignment properties.

Aug 9, 2012 at 8:18 AM

This is true, but if I render a vertical line, the text will also be vertical and I cannot find how to change this to a horizontal text with my vertical line. Is this possible?

I currently 'solve' this by adding a textannotation below the vertical line and leaving a space at the bottom of the line by giving it a minimumY

Coordinator
Aug 10, 2012 at 12:10 PM

Added a TextOrientation property in the LineAnnotation class.

Aug 10, 2012 at 12:31 PM

Thank you for the quick fix!

Aug 13, 2012 at 11:34 AM
Tech_Junkie wrote:

I am busy implementing a lineseries with two axes to show an overview of frequencies and their intensity. And until now I've used the styling as I've copied it from an example, in the definition of a lineseries:

LineSeries ls = new LineSeries()
{
    Color = OxyColors.Green,
    StrokeThickness = 2,
    MarkerType = MarkerType.Square,
    MarkerSize = 3,
    MarkerStroke = OxyColors.Black,
    MarkerStrokeThickness = 1
};
I was wondering if (and how) I can take these styling elements out of the code and put it in a styling in a xaml ResourceDictionary? Is this possible?

I see now that my second post apparently did not cover my complete question. Objo, would it be possible to do styling of elements in a plot out of the code, and in xaml?

Coordinator
Aug 23, 2012 at 2:59 PM

If you define your plot in XAML (WPF/SL) it should be possible to use a Style from a ResourceDictionary on the OxyPlot.Wpf.LineSeries. I have no example on this, but believe it should work. Let us know if there is a bug!

Aug 23, 2012 at 8:23 PM
Edited Aug 23, 2012 at 8:24 PM

Hi, I have already done this with WPF and it works fine!

Aug 23, 2012 at 8:24 PM

This discussion leads me to an additional question: Is it possible to define a line series (or in my case a plot model) with C# and to change the style afterwards with WPF xaml code? This way, we have a default style defined by the C# code, which can be overwritten later on. This yields more flexibility.

Coordinator
Aug 24, 2012 at 7:33 AM

You could override property metadata

http://msdn.microsoft.com/en-us/library/ms754209.aspx

but I don't think it is possible to mix a PlotModel and a Plot defined by XAML...

Aug 24, 2012 at 10:04 AM

Hi objo, I know this. Okay, it was just an idea but this realization leads to too much effort for me. In addition, I like brief and neat program code.