Placing marker at custom location
This discussion was imported from CodePlex
endorphing wrote at 2013-01-25 20:54:
Is there a way to place a marker at a custom location. If I had 5 points in my LineSeries, and I only want to put markers at the 2nd and 4th points, what's the best way to achieve that?
Thanks in advance for your help.
objo wrote at 2013-02-10 23:20:
I would add a ScatterSeries for the markers. The ScatterSeries class has more options for the markers. I don't think there should be more marker features in the LineSeries.
endorphing wrote at 2013-02-26 21:59:
Thanks for the tip. A ScatterSeries would work, except I need mouse events on the series to be enabled.
I ended up implementing a custom LineSeries. I re-defined the MarkerFill & MarkerStroke properties, so that setting them here doesn't enable markers in the base class.
I ended up implementing a custom LineSeries. I re-defined the MarkerFill & MarkerStroke properties, so that setting them here doesn't enable markers in the base class.
public class MarkerLineSeries : LineSeries
{
public IList<int> MarkerLocations { get; private set; }
new public OxyColor MarkerFill { get; set; }
new public OxyColor MarkerStroke { get; set; }
public MarkerLineSeries()
: this(string.Empty)
{
}
public MarkerLineSeries(string title)
: this(title, new Collection<int>())
{
}
public MarkerLineSeries(string title, IList<int> markerLocations)
: base(title)
{
MarkerLocations = markerLocations;
}
public override void Render(IRenderContext rc, PlotModel model)
{
base.Render(rc, model);
foreach (var location in MarkerLocations)
{
if (location < 0 || location > Points.Count - 1) break;
var pt = XAxis.Transform(Points[location].X, Points[location].Y, YAxis);
rc.DrawMarker(
pt,
GetClippingRect(),
MarkerType,
MarkerOutline,
MarkerSize,
MarkerFill,
MarkerStroke,
MarkerStrokeThickness);
}
}
}
Customer support service by UserEcho