Under review

Custom Markers

Oystein Bjorke 4 years ago • updated by anonymous 4 years ago 2
This discussion was imported from CodePlex

cwford wrote at 2012-04-25 20:50:

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.


objo wrote at 2012-04-25 21:28:

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;
        }


cwford wrote at 2012-04-26 00:59:

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

CodePlex
Hi,

I tried to do the same thing with PointAnnotation. But I could not find any outline property to set the custom marker outline to. I was wondering if you could tell how custom marker could be done with  PointAnnotation. 


            const int N = 6;<br>
            var customMarkerOutline = new ScreenPoint[N];<br>
            for (int i = 0; i < N; i++)<br>
            {<br>
                double th = Math.PI * (4.0 * i / (N - 1) - 0.5);<br>
                const double R = 1;<br>
                customMarkerOutline[i] = new ScreenPoint(Math.Cos(th) * R, Math.Sin(th) * R);<br>
            }<br>
var pointAnnotation2 = new PointAnnotation();<br>
            pointAnnotation2.X = 40;<br>
            pointAnnotation2.Y = 60;<br>
            pointAnnotation2.Shape = MarkerType.Custom;<br>
            pointAnnotation2.Stroke = OxyColors.DarkBlue;<br>
            pointAnnotation2.StrokeThickness = 1;<br>
            pointAnnotation2.Text = "Square";<br>
            MyModel.Annotations.Add(pointAnnotation2);<br>


Under review
I see there is no custom outline property for the `PointAnnotation`. 
I have added issue #174