Search code examples
c#wpfoxyplot

Oxyplot distance between ticks


How to decrease distance between ticks? I want to place candles more closely. And i cannot find any property in LinearAxis XAxis that respond for distance.

enter image description here

Code:

namespace WpfApplication20
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
/// 
public partial class MainWindow : Window
{

    public MainWindow()
    {
        InitializeComponent();
        DataContext = new PlotClass();
    }

}
public class PlotClass
{
    public PlotModel PlotModel { get; set; }
    public PlotClass()
    {
        Random rnd = new Random();
        PlotModel = new PlotModel();
        LineSeries LS = new LineSeries();
        LinearAxis XAxis = new LinearAxis
        {
            Position = AxisPosition.Bottom,
            MinorStep=1,
            MajorStep=1

        };
        LinearAxis YAxis = new LinearAxis()
        {
            Position = AxisPosition.Left
        };
        for (int i=0;i<10;i++)
        {
            LS.Points.Add(new DataPoint(i,rnd.Next(1,10)));
        }
        PlotModel.Axes.Add(YAxis);
        PlotModel.Axes.Add(XAxis);
        PlotModel.Series.Add(LS);
        ChangeToCandles();
        WhatTypeOfSeries();
    }
    public void ChangeToCandles()
    {
        Random rnd = new Random();
        PlotModel.Series.Clear();
        CandleStickSeries CSS = new CandleStickSeries();
        for (int i = 0; i < 10;i++ )
        {
            CSS.Items.Add(new HighLowItem { X = i, Close = rnd.NextDouble(), High = rnd.NextDouble(), Low = rnd.NextDouble(), Open = rnd.NextDouble() });
        }
        PlotModel.Series.Add(CSS);
    }
    public void WhatTypeOfSeries()
    {
        var temp = PlotModel.Series[0].GetType();
        Console.WriteLine(temp);
    }
}
}

xaml:

 <Grid>
    <oxy:Plot Model="{Binding PlotModel}"/>
</Grid>

Solution

  • Try zooming:

    XAxis.Zoom(-5, 15);
    

    EDIT>>>>

    You have a for loop from 0 to 10, you just have to add some adjust values. For that limits for being more generic:

    int lowerIndex = 0;
    int upperIndex = 10;
    int zoomValue = 5;
    
    for (int i=lowerIndex;i<upperIndex;i++)
    {
        LS.Points.Add(new DataPoint(i,rnd.Next(1,10)));
    }
    
    XAxis.Zoom(lowerIndex-zoomValue, upperIndex+zoomValue);