Y 轴在折线图上的最大值处
Y Axis at max values on line graph
我有一个带有十字线的折线图,我想知道 y 轴十字线(水平)是否可能只沿着折线图的最大值移动。如果我的描述没有解决我的问题,希望这些图片能有所帮助?
图片 1
图 2
我想知道是否可以显示这个,因为目前我需要将鼠标移动到 40 到 60 之间的点来实现这个外观,是否可以在无需调整的情况下获得这个结果我自己十字准线?
Xaml
<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#
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);
}
}
这可能对控件供应商有所帮助....
Or this one, Strip Lines, you can adjust style
使用专有控件时,请先向供应商寻求支持和教程。
我有一个带有十字线的折线图,我想知道 y 轴十字线(水平)是否可能只沿着折线图的最大值移动。如果我的描述没有解决我的问题,希望这些图片能有所帮助?
图片 1
我想知道是否可以显示这个,因为目前我需要将鼠标移动到 40 到 60 之间的点来实现这个外观,是否可以在无需调整的情况下获得这个结果我自己十字准线?
Xaml
<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#
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);
}
}
这可能对控件供应商有所帮助....
Or this one, Strip Lines, you can adjust style
使用专有控件时,请先向供应商寻求支持和教程。