Custom Markers

Apr 25, 2012 at 7:50 PM

I would very much appreciate anyone who could demonstrate in code how to create a custom marker for OxyPlot in Sliverlight. The browser example displays a "star" marker but there is not indication in the method that implements this example of how the custom marker is created.

 

Thank you.

Apr 25, 2012 at 8:28 PM

See Source\Examples\ExampleLibrary\Examples\LineSeriesExamples.cs

The custom markers are currently limited to a single, continuous outline.

        [Example("Custom markers")]
        public static PlotModel CustomMarkers()
        {
            var model = new PlotModel("LineSeries with custom markers") { LegendSymbolLength = 30, PlotType = PlotType.Cartesian };
            const int N = 6;
            var customMarkerOutline = new ScreenPoint[N];
            for (int i = 0; i < N; i++)
            {
                double th = Math.PI * (4.0 * i / (N - 1) - 0.5);
                const double R = 1;
                customMarkerOutline[i] = new ScreenPoint(Math.Cos(th) * R, Math.Sin(th) * R);
            }

            var s1 = new LineSeries("Series 1")
                         {
                             Color = OxyColors.Red,
                             StrokeThickness = 2,
                             MarkerType = MarkerType.Custom,
                             MarkerOutline = customMarkerOutline,
                             MarkerFill = OxyColors.DarkRed,
                             MarkerStroke = OxyColors.Black,
                             MarkerStrokeThickness = 0,
                             MarkerSize = 10
                         };

            foreach (var pt in customMarkerOutline)
            {
                s1.Points.Add(new DataPoint(pt.X, -pt.Y));
            }

            model.Series.Add(s1);

            return model;
        }

Apr 25, 2012 at 11:59 PM

objo,

Wow! Thanks for being so responsive. Have played around with the code and understand now that you kept XAML to a minimum so it could follow MVVM pattern.

Thank you for the code for the custom markers.

 

Clyde