Y轴在线图上的最大值

时间:2015-11-03 16:09:56

标签: wpf charts syncfusion

我有一个十字线的折线图,我想知道y轴十字线(水平)是否可能只沿着折线图的最大值移动。如果我的描述没有解决我的问题,希望这些图像会有帮助吗?

图片1 enter image description here 图片2 enter image description here

我想知道是否可以将其显示为当前我需要将鼠标移动到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);
    }
}

1 个答案:

答案 0 :(得分:1)

这可能对控件的供应商有帮助....

Vendor Help page

Or this one, Strip Lines, you can adjust style

使用专有控件时,请先向供应商寻求支持和教程。