1

I have a line graph with a cross hair and I am wondering is it possible for the y axis cross hair (horizontal) to only move along the maximum values of a line graph. If my description isn't clearing my problem up hopefully these images will help?

Image 1 enter image description here Image 2 enter image description here

I am wondering if it is possible to have this displayed as currently I need to move the mouse up to the point from 40 to 60 to achieve this look, is it possible to do get this result without me having to adjust the cross hair myself?

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>

Edit 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);
    }
}
Ryan Archibald
  • 215
  • 2
  • 18
  • I believe you can set the horizontal to the max Y axis value. – htm11h Nov 03 '15 at 16:12
  • Where about do you set this exactly? Just I've only just started learning about all this – Ryan Archibald Nov 03 '15 at 16:15
  • Where are you managing the data, do you have a code behind page in C# or Vb? – htm11h Nov 03 '15 at 16:16
  • Yeah I have code behind page in C#, I'll attach it on the edit – Ryan Archibald Nov 03 '15 at 16:17
  • I don't have any chart tools in my VS currently, but you can actually draw a line at the max value. I might be able to pull up an old project and post something, but it will be awhile. Assign the YData max value to another variable. Here are 2 links to investigate: https://msdn.microsoft.com/en-us/library/aa287522%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396, http://stackoverflow.com/questions/21990022/add-horizontal-line-to-chart-in-c-sharp – htm11h Nov 03 '15 at 16:27
  • Ok thanks a lot I'll have a look at them and start trying things out – Ryan Archibald Nov 03 '15 at 16:29

1 Answers1

2

This might be helpful from the control's vendor....

Vendor Help page

Or this one, Strip Lines, you can adjust style

When using proprietary controls, look to the vendor first for support and tutorials.

htm11h
  • 1,739
  • 8
  • 47
  • 104