1增加Y轴标题左右切换;

2增加实时数据刷新时间设置;
3修改x轴平移,缩放等;
master
mzhifa 2 years ago
parent cdcae12502
commit 2b8c399b0d

@ -22,7 +22,7 @@ namespace mseedChart.MainModule.Models
List<AxisY> axisYList = new List<AxisY>();
foreach (var item in stationModels)
{
int distancetoX= -(int)curChart.ActualWidth + 80;
int distancetoX= SetYasixPlacement(curChart);
AxisY axisY = new AxisY(curChart.ViewXY);
//添加Z分量波形
if (item.dz.Count > 0)
@ -55,6 +55,19 @@ namespace mseedChart.MainModule.Models
}
return axisYList;
}
public int SetYasixPlacement(LightningChart chart)
{
int distancetoX = 0;
if (chart.ViewXY.AxisLayout.YAxisAutoPlacement == YAxisAutoPlacement.AllLeft)
{
distancetoX = -(int)chart.ActualWidth + 70;
}
else if (chart.ViewXY.AxisLayout.YAxisAutoPlacement == YAxisAutoPlacement.AllRight)
{
distancetoX = (int)chart.ActualWidth-2*60;
}
return distancetoX;
}
public List<AxisY> CreateAxisYEventTime(StationEventJson stationEventJson, ViewXY chartV, List<StationModel> stationModels)
{

@ -44,8 +44,9 @@ namespace mseedChart.MainModule.ViewModels
_dispatcher = Application.Current.Dispatcher;
_wavesModel = new WavesModel();
(Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose;
IntervalTime=100;
CreateChart();
}
#region 字段
@ -55,9 +56,11 @@ namespace mseedChart.MainModule.ViewModels
int _samplingFrequency = 500; // 采样频率 (Hz).
WavesModel _wavesModel;
private int _lChartCount = 1;
public ConcurrentQueue<StationModel> smList;
public ConcurrentQueue<StationModel> smList=new ConcurrentQueue<StationModel>();
public List<AxisY> _chartAxisY=new List<AxisY>();
private DispatcherTimer dispatcherTimer=new DispatcherTimer();
#endregion
#region 属性
@ -144,6 +147,40 @@ namespace mseedChart.MainModule.ViewModels
SetProperty(ref _currentTime, value);
}
}
private YAxisAutoPlacement _yaxisPlacement;
public YAxisAutoPlacement YaxisPlacement
{
get { return _yaxisPlacement; }
set
{
LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = value;
int distancetoX =_wavesModel.SetYasixPlacement(LChartALL);
foreach (var item in LChartALL.ViewXY.YAxes)
{
item.Title.DistanceToAxis = distancetoX;
}
SetProperty(ref _yaxisPlacement, value);
}
}
private int _IntervalTime=10;
public int IntervalTime
{
get { return _IntervalTime; }
set
{
if (value >=10)
{
dispatcherTimer.Interval = TimeSpan.FromMilliseconds(value);
}
SetProperty(ref _IntervalTime, value);
}
}
#endregion
#region 事件
@ -200,6 +237,8 @@ namespace mseedChart.MainModule.ViewModels
st.Stop();
Debug.WriteLine("统计时间StartChart************{0}", st.Elapsed);
FeedDatasToChart();
_wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList());
}
}
@ -355,21 +394,28 @@ namespace mseedChart.MainModule.ViewModels
if (_lChartAll != null)
{
bool yAxesVisible = ((bool)isCheck == true);
if (smList.Count == 0)
{
return;
}
_lChartAll.BeginUpdate();
if (yAxesVisible)
{
StartChart();
//Set real-time monitoring automatic old data destruction
LChartALL.ViewXY.DropOldSeriesData = true;
_pointsAppended = LChartALL.ViewXY.XAxes[0].Minimum;
CompositionTarget.Rendering -= CompositionTarget_Rendering;
CompositionTarget.Rendering += CompositionTarget_Rendering;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
dispatcherTimer.Tick += CompositionTarget_Rendering;
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.Scrolling;
dispatcherTimer.Start();
}
else
{
dispatcherTimer.Stop();
LChartALL.ViewXY.XAxes[0].ScrollMode = XAxisScrollMode.None;
CompositionTarget.Rendering -= CompositionTarget_Rendering;
dispatcherTimer.Tick -= CompositionTarget_Rendering;
}
_lChartAll.EndUpdate();
@ -395,18 +441,18 @@ namespace mseedChart.MainModule.ViewModels
LChartALL.ViewXY.AxisLayout.SegmentsGap = 0;
LChartALL.ViewXY.ZoomPanOptions.PanDirection = PanDirection.Horizontal;
LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Horizontal;
LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllLeft;
LChartALL.ViewXY.AxisLayout.YAxisAutoPlacement = YAxisAutoPlacement.AllRight;
LChartALL.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false;
LChartALL.ViewXY.AxisLayout.AutoAdjustMargins = false;
LChartALL.ViewXY.ZoomPanOptions.DevicePrimaryButtonAction = UserInteractiveDeviceButtonAction.None;
LChartALL.ViewXY.ZoomPanOptions.DevicePrimaryButtonAction = UserInteractiveDeviceButtonAction.Pan;
LChartALL.ViewXY.ZoomPanOptions.DeviceSecondaryButtonAction = UserInteractiveDeviceButtonAction.None;
LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Off;
LChartALL.ViewXY.ZoomPanOptions.WheelZooming = WheelZooming.Horizontal;
// 反锯齿系数。值0和1都不会应用反锯齿
LChartALL.ChartRenderOptions.AntiAliasLevel = 0;
//X轴设置
LChartALL.ViewXY.XAxes[0].AllowScrolling = false;
LChartALL.ViewXY.XAxes[0].PanningEnabled = false;
LChartALL.ViewXY.XAxes[0].AllowScrolling = true;
LChartALL.ViewXY.XAxes[0].PanningEnabled = true;
LChartALL.ViewXY.XAxes[0].MajorGrid.Pattern = LinePattern.Solid;
LChartALL.ViewXY.XAxes[0].ValueType = AxisValueType.DateTime;
LChartALL.ViewXY.XAxes[0].KeepDivCountOnRangeChange = true;
@ -435,10 +481,14 @@ namespace mseedChart.MainModule.ViewModels
ViewXY v = LChartALL.ViewXY;
LChartALL.SizeChanged -= LChartALL_SizeChanged;
LChartALL.SizeChanged += LChartALL_SizeChanged;
LChartALL.ViewXY.Zoomed -= ViewXY_Zoomed;
LChartALL.ViewXY.Zoomed += ViewXY_Zoomed;
LChartALL.ViewXY.Panned -= ViewXY_Panned;
LChartALL.ViewXY.Panned += ViewXY_Panned;
DisposeAllAndClear(v.YAxes);
DisposeAllAndClear(v.SampleDataSeries);
DisposeAllAndClear(v.LineCollections);
v.Margins=new Thickness(80, 30, 50, 60);
v.Margins=new Thickness(60, 30, 60, 60);
v.YAxes.AddRange(_wavesModel.CreateYAxisChart(smList.ToList(), LChartALL));
v.LegendBoxes[0].Position = LegendBoxPositionXY.RightCenter;
@ -520,16 +570,33 @@ namespace mseedChart.MainModule.ViewModels
}
}
private void ViewXY_Panned(object sender, PannedXYEventArgs e)
{
foreach (var item in LChartALL.ViewXY.LineCollections)
{
double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80;
item.Title.Offset.SetValues((int)b, 3);
}
}
private void ViewXY_Zoomed(object sender, ZoomedXYEventArgs e)
{
foreach (var item in LChartALL.ViewXY.LineCollections)
{
double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX) - 80;
item.Title.Offset.SetValues((int)b, 3);
}
}
private void LChartALL_SizeChanged(object sender, SizeChangedEventArgs e)
{
int distancetoX = _wavesModel.SetYasixPlacement(LChartALL);
foreach (var item in LChartALL.ViewXY.YAxes)
{
//更新标题坐标
item.Title.DistanceToAxis = -(int)e.NewSize.Width+80;
item.Title.DistanceToAxis = distancetoX;
}
foreach (var item in LChartALL.ViewXY.LineCollections)
{
double b = LChartALL.ViewXY.XAxes[0].ValueToCoordD(item.Lines[0].AX)-80;
item.Title.Offset.SetValues((int)b, 3);
}
@ -550,7 +617,6 @@ namespace mseedChart.MainModule.ViewModels
_dispatcher.Invoke(() =>
{
LChartALL.BeginUpdate();
_wavesModel.CreateAxisYEventTime(CurrentEventTime, LChartALL.ViewXY, smList.ToList());
for (int channelIndex = 0; channelIndex < _channelCount; channelIndex++)
{
LChartALL.ViewXY.SampleDataSeries[channelIndex].AddSamples(_data[channelIndex], true);

@ -42,11 +42,12 @@
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" IsChecked="True" Content="SHN" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<CheckBox Command="{Binding YasixZENVisibleCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self}}" IsChecked="True" Content="SHE" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" Margin="5,0,5,0" FontWeight="Bold"></CheckBox>
<TextBlock VerticalAlignment="Center">X轴间隔:</TextBlock>
<TextBox Text="{Binding XaisInterval}" Width="80" VerticalAlignment="Center"></TextBox>
<TextBox Text="{Binding XaisInterval}" Width="60" VerticalAlignment="Center"></TextBox>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding IntervalSureCommand}" Margin="10,0,10,0" Background="#FF66B1FF" HorizontalAlignment="Right" Height="20" Width="30">OK</Button>
<CheckBox IsChecked="{Binding IsMultFiles}" Content="MultFiles" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontWeight="Bold" DockPanel.Dock="Right"></CheckBox>
<Button Grid.Column="1" Grid.Row="1" Command="{Binding FileSelectorCommand}" Margin="5,0,20,0" Background="#FF66B1FF" HorizontalAlignment="Right" Width="60" Height="20">打开</Button>
<CheckBox Command="{Binding RealTimeDataCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Mode=Self},Path=IsChecked}" Content="实时" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontWeight="Bold" DockPanel.Dock="Right"></CheckBox>
<TextBox Text="{Binding IntervalTime}" Width="60" VerticalAlignment="Center"></TextBox>
</StackPanel>
<ContentControl x:Name="contentControl" Content="{Binding ChildContent}" Grid.Row="1"/>
<TextBlock Text="{Binding CurrentTime}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,46"></TextBlock>

Loading…
Cancel
Save