【问题标题】:Oxyplot distance between ticks刻度之间的 Oxyplot 距离
【发布时间】:2015-11-06 19:01:14
【问题描述】:

如何减少刻度之间的距离?我想把蜡烛放得更近一些。 我在LinearAxis XAxis 中找不到任何响应距离的属性。

代码:

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>

【问题讨论】:

    标签: c# wpf oxyplot


    【解决方案1】:

    尝试缩放:

    XAxis.Zoom(-5, 15);
    

    编辑>>>>

    你有一个从 0 到 10 的 for 循环,你只需要添加一些调整值。对于更通用的限制:

    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);
    

    【讨论】:

    • 它不应该改变刻度之间的距离。
    • 我已经对其进行了测试,并且确实如此,至少在您的情况下。
    【解决方案2】:

    尝试使用CandleStickSeries.CandleWidth属性:

    1. 如果设置为 1,那么蜡烛之间将没有空间。
    2. 如果将其设置为 > 1,则蜡烛将重叠。
    3. 如果将其设置为值

    【讨论】: