I have a line series chart with 24 data points and I'm trying to add some UI features, like being able to update a data point by clicking on the data point moving it up and down. I don't have the conversion from screen pixels to data values and I'm not worried about that right now. I'm just trying to make the point move up and down with mouse event triggers. My problem is that the point only updates when I move the mouse down and not up.
C# code for the mouse trigger events
decimal preMouse;
decimal change;
private void MyChart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var p = Mouse.GetPosition(this.canvas);
preMouse = System.Convert.ToDecimal(p.Y);
// Real data Value
var realvalue = vm.ObsLoadChartData.ElementAt(1).Value;
}
private void MyChart_MouseMove(object sender, MouseEventArgs e)
{
var currentP = Mouse.GetPosition(this.canvas);
var currentY = System.Convert.ToDecimal(currentP.Y);
change = currentY - preMouse;
}
private void MyChart_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
var newvalue = change * 50;
var prop = typeof(ProbeLoadData).GetProperty("Hr" + "2");
var realvalue = vm.ObsLoadChartData.ElementAt(1).Value;
prop.SetValue(vm.obsSelectedLoadForecast.ObsForecast, realvalue + newvalue, null);
}
WPF Code for the chart
<Grid x:Name="MyGrid" Grid.Row="2" Background="#3A3A3A">
<Canvas x:Name="canvas">
<charting:Chart x:Name="MyChart" Title="{Binding ObsSelectedLoadForecast.ObsForecast.ZoneName, TargetNullValue=RTO, FallbackValue=RTO}" Grid.Row="1" SnapsToDevicePixels="True" Foreground="White" BorderThickness="0" Height="372" Width="1613" MouseLeftButtonDown="MyChart_MouseLeftButtonDown" MouseLeftButtonUp="MyChart_MouseLeftButtonUp" MouseMove="MyChart_MouseMove">
<charting:Chart.PlotAreaStyle>
<Style TargetType="{x:Type Grid}">
<Setter Property="Background" Value="{x:Null}" />
</Style>
</charting:Chart.PlotAreaStyle>
<charting:Chart.Axes>
<charting:LinearAxis Orientation="X" ShowGridLines="False" Interval="1" />
<charting:LinearAxis Orientation="Y" ShowGridLines="False" />
</charting:Chart.Axes>
<charting:Chart.Series>
<charting:LineSeries ItemsSource="{Binding ObsLoadChartData}"
IndependentValuePath="Hour"
DependentValuePath="Value" Name="lineSeries">
</charting:LineSeries>
</charting:Chart.Series>
</charting:Chart>
</Canvas>
</Grid>