Wpf 线图上最大值处的Y轴
我有一个带有十字线的线形图,我想知道y轴十字线(水平)是否可能只沿着线形图的最大值移动。如果我的描述不能解决我的问题,希望这些图片能有所帮助 图像1 图像2 我想知道是否有可能显示这一点,因为目前我需要将鼠标从40移动到60以实现此外观,是否有可能在不需要我自己调整十字线的情况下获得此结果 XamlWpf 线图上最大值处的Y轴,wpf,charts,syncfusion,Wpf,Charts,Syncfusion,我有一个带有十字线的线形图,我想知道y轴十字线(水平)是否可能只沿着线形图的最大值移动。如果我的描述不能解决我的问题,希望这些图片能有所帮助 图像1 图像2 我想知道是否有可能显示这一点,因为目前我需要将鼠标从40移动到60以实现此外观,是否有可能在不需要我自己调整十字线的情况下获得此结果 Xaml <Grid> <Grid.DataContext> <local:ViewModel/> </Grid.DataC
<Grid>
<Grid.DataContext>
<local:ViewModel/>
</Grid.DataContext>
<syncfusion:SfChart Margin="10">
<syncfusion:SfChart.PrimaryAxis>
<syncfusion:CategoryAxis />
</syncfusion:SfChart.PrimaryAxis>
<syncfusion:SfChart.SecondaryAxis>
<syncfusion:NumericalAxis Maximum="80" Minimum="0"/>
</syncfusion:SfChart.SecondaryAxis>
<syncfusion:SfChart.Behaviors>
<local:CustomCrossHairBehavior />
</syncfusion:SfChart.Behaviors>
<syncfusion:LineSeries x:Name="series"
ItemsSource="{Binding DataPoint}"
XBindingPath="XData"
YBindingPath="YData"/>
</syncfusion:SfChart>
</Grid>
编辑C#
公共类模型
{
公共字符串扩展数据
{
得到;
设置
}
公共双YData
{
得到;
设置
}
}
公共类视图模型
{
公共可观测收集数据点
{
得到;
设置
}
公共视图模型()
{
this.DataPoint=新的ObservableCollection();
var date=新的日期时间(2000,1,1);
添加(新模型{XData=“Jan”,YData=40});
添加(新模型{XData=“Feb”,YData=60});
添加(新模型{XData=“Mar”,YData=30});
添加(新模型{XData=“Apr”,YData=20});
添加(新模型{XData=“May”,YData=60});
添加(新模型{XData=“June”,YData=50});
添加(新模型{XData=“July”,YData=10});
添加(新型号{XData=“August”,YData=40});
}
}
公共类CustomCrossHairBehavior:ChartTrackBallBehavior
{
公共线路新线;
公众行为
{
换行符=换行符();
绑定=新绑定();
binding.Path=newpropertypath(“LineStyle”);
binding.Source=this;
newline.SetBinding(Line.StyleProperty,binding);
}
MouseMove上的受保护覆盖无效(MouseEventArgs e)
{
var元素=e.源为SfChart;
var position=e.GetPosition(this.AdorningCanvas);
newline.X1=ChartArea.seriesliprect.Left;
换行符.Y1=位置.Y;
newline.Y2=position.Y;
newline.X2=ChartArea.SeriesClipRect.Width+ChartArea.SeriesClipRect.Left;
加法(换行);
基地移动(e);
}
}
控件的供应商可能会对此有所帮助
使用专有控件时,请首先向供应商寻求支持和教程。我相信您可以将水平设置为最大Y轴值。您具体在哪里设置?只是我刚刚开始了解所有这些,你在哪里管理数据,你有C#或Vb中的代码隐藏页吗?是的,我有C#中的代码隐藏页,我会将其附加到编辑器上。我的VS中目前没有任何图表工具,但你可以在最大值处画一条线。我可能会调出一个旧项目并发布一些东西,但这需要一段时间。将YData max值指定给另一个变量。这里有两个链接需要调查:,好的,谢谢,我正在查看它们,如果其中一个有效,我会告诉你
public class Model
{
public string XData
{
get;
set;
}
public double YData
{
get;
set;
}
}
public class ViewModel
{
public ObservableCollection<Model> DataPoint
{
get;
set;
}
public ViewModel()
{
this.DataPoint = new ObservableCollection<Model>();
var date = new DateTime(2000, 1, 1);
DataPoint.Add(new Model { XData = "Jan", YData = 40});
DataPoint.Add(new Model { XData = "Feb", YData = 60});
DataPoint.Add(new Model { XData = "Mar", YData = 30});
DataPoint.Add(new Model { XData = "Apr", YData = 20});
DataPoint.Add(new Model { XData = "May", YData = 60});
DataPoint.Add(new Model { XData = "June", YData = 50});
DataPoint.Add(new Model { XData = "July", YData = 10});
DataPoint.Add(new Model { XData = "August", YData = 40});
}
}
public class CustomCrossHairBehavior:ChartTrackBallBehavior
{
public Line newline;
public CustomCrossHairBehavior()
{
newline = new Line();
Binding binding = new Binding();
binding.Path = new PropertyPath("LineStyle");
binding.Source = this;
newline.SetBinding(Line.StyleProperty, binding);
}
protected override void OnMouseMove(MouseEventArgs e)
{
var element = e.Source as SfChart;
var positon = e.GetPosition(this.AdorningCanvas);
newline.X1 = ChartArea.SeriesClipRect.Left;
newline.Y1 = positon.Y;
newline.Y2 = positon.Y;
newline.X2 = ChartArea.SeriesClipRect.Width + ChartArea.SeriesClipRect.Left;
AddElement(newline);
base.OnMouseMove(e);
}
}