Вот мой код:
Код: Выделить всё
public PlotViewModel()
{
InitializeRenderingLoop();
// Initialize SpectralPlotModel
SpectralPlotModel = new PlotModel
{
Title = "Data from Socket",
Background = OxyColors.Transparent,
TextColor = OxyColors.White,
PlotAreaBorderColor = OxyColors.White
};
SpectralPlotModel.Axes.Add(new LinearAxis
{
Position = AxisPosition.Bottom,
Title = "Wavelength",
TitleColor = OxyColors.White,
AxislineColor = OxyColors.White,
TextColor = OxyColors.White,
StringFormat = "0.###",
});
SpectralPlotModel.Axes.Add(new LinearAxis
{
Position = AxisPosition.Left,
Title = "Data",
TitleColor = OxyColors.White,
AxislineColor = OxyColors.White,
TextColor = OxyColors.White,
StringFormat = "0.###",
Minimum = 0,
Maximum = 5
});
SpectralPlotModel.Series.Add(new LineSeries
{
Title = "Data",
Color = OxyColors.White,
MarkerFill = OxyColors.White,
MarkerType = MarkerType.None,
LineStyle = LineStyle.Solid,
StrokeThickness = 2
});
SpectralPlotModel.Series.Add(new LineSeries
{
Title = "Red Line",
Color = OxyColors.Red,
MarkerFill = OxyColors.Red,
MarkerType = MarkerType.Cross,
LineStyle = LineStyle.Solid,
StrokeThickness = 15,
});
}
Код: Выделить всё
public double WavelengthSliderValue
{
get => _wavelengthSliderValue;
set
{
if (_wavelengthSliderValue != value)
{
_wavelengthSliderValue = value;
OnPropertyChanged();
UpdateRedLine();
}
}
}
public void UpdateRedLine()
{
if (SpectralPlotModel != null && SpectralPlotModel.Series.Count > 1)
{
var redLineSeries = SpectralPlotModel.Series[1] as LineSeries;
if (redLineSeries != null)
{
var selectedWavelength = WavelengthSliderValue;
Debug.Print("Wavelength : " + selectedWavelength);
// Clear existing points
redLineSeries.Points.Clear();
// Ensure the axis limits are correct
var yAxis = SpectralPlotModel.Axes[1];
redLineSeries.Points.Add(new DataPoint(selectedWavelength, yAxis.Minimum)); // Min Y
redLineSeries.Points.Add(new DataPoint(selectedWavelength, yAxis.Maximum)); // Max Y
SpectralPlotModel.InvalidatePlot(true);
}
else
{
Debug.Write("No red line series found");
}
}
}
Код: Выделить всё
Я неправильно установил?
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/789 ... e-the-plot