A forum dedicated to WPF version of LightningChart Ultimate.
Moderator: Queue Moderators
-
symbolick
- Posts: 52
- Joined: Thu May 16, 2013 8:24 pm
Post
by symbolick » 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.
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();
}
}
Any suggestions on how to get this behavior working?
Regards,
Aaron
-
ArctionJari
Post
by ArctionJari » Wed Oct 30, 2013 8:19 am
Hi Aaron.
You did not convert the mouse position coordinate to actual axis value using axis' CoordToValue. Also, when you create a series, make sure that it is assigned to one X and Y axis (either using series' constructor parameters or setting AssignXAxisIndex and AssignYAxisIndex). If you don't, series won't get rendered. You should also set ViewXY.ZoomPanOptions.RightMouseButtonAction to None so that panning does not change the range while you draw the line.
Here are modified mouse event handlers:
Code: Select all
private void lightningChart1_MouseDown(object sender, MouseButtonEventArgs e)
{
if (Mouse.RightButton == MouseButtonState.Pressed)
{
Point _originalPoint = e.GetPosition(lightningChart1);
Double dXValue;
Double dYValue;
lightningChart1.ViewXY.XAxes[0].CoordToValue((Int32)_originalPoint.X, out dXValue, false);
lightningChart1.ViewXY.YAxes[0].CoordToValue((Single)_originalPoint.Y, out dYValue);
lightningChart1.BeginUpdate();
if (lightningChart1.ViewXY.FreeformPointLineSeries.Contains(_selectionSeries) == false)
{
lightningChart1.ViewXY.FreeformPointLineSeries.Add(_selectionSeries);
}
SeriesPoint[] thisPoint = new SeriesPoint[1];
thisPoint[0].X = dXValue;
thisPoint[0].Y = dYValue;
_selectionSeries.AddPoints(thisPoint, false);
lightningChart1.EndUpdate();
}
}
private void lightningChart1_MouseMove(object sender, MouseEventArgs e)
{
if (Mouse.RightButton == MouseButtonState.Pressed)
{
Point pnScreen = e.GetPosition(lightningChart1);
Double dXValue;
Double dYValue;
lightningChart1.ViewXY.XAxes[0].CoordToValue((Int32)pnScreen.X, out dXValue, false);
lightningChart1.ViewXY.YAxes[0].CoordToValue((Single)pnScreen.Y, out dYValue);
lightningChart1.BeginUpdate();
SeriesPoint[] thisPoint = new SeriesPoint[1];
thisPoint[0].X = dXValue;
thisPoint[0].Y = dYValue;
_selectionSeries.AddPoints(thisPoint, false);
lightningChart1.EndUpdate();
}
}
I hope this solves the problem you are having. I created a test project and the "selection line" was drawn correctly.
-
symbolick
- Posts: 52
- Joined: Thu May 16, 2013 8:24 pm
Post
by symbolick » Wed Oct 30, 2013 6:33 pm
Thanks for your help, that did fix the issue.
Regards,
Aaron