Drawing on the chart
Posted: Tue Oct 29, 2013 4:14 pm
I am attempting to tie into the chart.MouseDown and chart.MouseMove events in order to allow the user to draw a shape on the chart. The desired goal of this is to then run a algorithm on the shape drawn to select data contained within the shape. However when adding points to the FreeFormPointLineSeries im using, nothing is being drawn on the screen even though I can see the points being added in the watch.
below is the code im using to instantiate the FreeFormLineSeries and the two mouse events im trying to draw with.
Any suggestions on how to get this behavior working?
Regards,
Aaron
below is the code im using to instantiate the FreeFormLineSeries and the two mouse events im trying to draw with.
Code: Select all
LineStyle _selectionStyle = new LineStyle
{
Color = Colors.Black,
Width = 5,
Pattern = LinePattern.Solid
};
FreeformPointLineSeries _selectionSeries = new FreeformPointLineSeries { LineVisible = true, PointsVisible = false};
void _chart_MouseDown(object sender, MouseButtonEventArgs e)
{
if (Mouse.RightButton == MouseButtonState.Pressed)
{
_originalPoint = e.GetPosition(_chart);
_chart.BeginUpdate();
_selectionSeries.LineStyle = _selectionStyle;
_selectionSeries.Visible = true;
_selectionSeries.MouseInteraction = false;
if (!_chart.ViewXY.FreeformPointLineSeries.Contains(_selectionSeries))
_chart.ViewXY.FreeformPointLineSeries.Add(_selectionSeries);
SeriesPoint[] thisPoint = new SeriesPoint[1];
thisPoint[0].X = (double)_originalPoint.X;
thisPoint[0].Y = (double)_originalPoint.Y;
_selectionSeries.AddPoints(thisPoint,false);
_chart.FullRepaint();
_chart.InvalidateVisual();
_chart.EndUpdate();
}
}
void _chart_MouseMove(object sender, MouseEventArgs e)
{
if (Mouse.RightButton == MouseButtonState.Pressed)
{
Point pnScreen = e.GetPosition(_chart);
//_originalPoint = e.GetPosition(_chart);
_chart.BeginUpdate();
SeriesPoint[] thisPoint = new SeriesPoint[1];
thisPoint[0].X = (double)pnScreen.X;
thisPoint[0].Y = (double)pnScreen.Y;
_selectionSeries.AddPoints(thisPoint, false);
_chart.FullRepaint();
_chart.InvalidateVisual();
_chart.EndUpdate();
}
}
Regards,
Aaron