首页 文章

当设置具有较大值的OxyPlot对数x轴并且PlotType设置为使用笛卡尔选项时,图表曲线丢失

提问于
浏览
1

我使用wpf oxyplot并设置x轴以使用对数 .

我使用mvvm而不是代码风格 .

这是我在vm的 property

public PlotModel ChartPlot
        {
            get { return _chartPlot; }
            set { _chartPlot = value; RaisePropertyChanged(() => ChartPlot); }
        }

WPF

<oxy:PlotView Grid.Row="1" Grid.Column="1" Model="{Binding ChartPlot}" /> 




//--- here is  _bigDataPoints data list of points

     var _bigDataPoints     = new List<DataPoints>();

//                  #x1 double          #y double

    _bigDataPoints.Add(410.8070281  ,   4943000.0000000 );
    _bigDataPoints.Add(432.7935746  ,   5041000.0000000 );
    _bigDataPoints.Add(436.8319199  ,   5059000.0000000 );
    _bigDataPoints.Add(9918.193582  ,   47320000.0000000 );
    _bigDataPoints.Add(10099.91912  ,   48130000.0000000 );
    _bigDataPoints.Add(10216.58243  ,   48650000.0000000 );
    _bigDataPoints.Add(104904.5616  ,   470700000.0000000 );
    _bigDataPoints.Add(107282.6983  ,   481300000.0000000 );
    _bigDataPoints.Add(108337.1551  ,   486000000.0000000 );
    _bigDataPoints.Add(991388.6853  ,   4422000128.0000000 );
    _bigDataPoints.Add(1000362.786  ,   4462000128.0000000 );
    _bigDataPoints.Add(1006195.923  ,   4488000000 );

    var logAxisX = new LogarithmicAxis() { Position = AxisPosition.Bottom, Title = "Log(x)", UseSuperExponentialFormat = false, Base = 10 };
    var linearAxisY = new LinearAxis() { Position = AxisPosition.Left, Title = "Y", UseSuperExponentialFormat = false };

// PlotModel ChartPlot = new PlotModel(); -> this is property that is binding to oxyplot control

    ChartPlot.Axes.Add(linearAxisY);
    ChartPlot.Axes.Add(logAxisX);

    var lineSeriesBigData = new OxyPlot.Series.LineSeries();
    lineSeriesBigData.Points.AddRange(_bigDataPoints);

    ChartPlot.Series.Clear();
    ChartPlot.Annotations.Clear();
    ChartPlot.Series.Add(lineSeriesBigData);  

// refresh chart
ChartPlot.InvalidatePlot(true);

曲线完全缺失,为什么?我为图表轴设置了最小/最大间隔,但图表上仍然缺少线性曲线 . 其他的错误是x轴无法用鼠标拖动 . 它似乎是轴冻结 . 如果我设置x轴的最大值,他在x轴上没有显示正确的最大值 . 显示100,为什么? y轴没问题

https://github.com/oxyplot/oxyplot/issues/900

2 回答

  • 0

    您缺少将 PlotModel 分配给 PlotView ,如下所示:

    XAML:

    <Window
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApplication3"
            xmlns:oxy="http://oxyplot.org/wpf" 
            x:Class="WpfApplication3.MainWindow"
            mc:Ignorable="d"
            Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
        <Grid>
    
            <oxy:PlotView Name="plotView1" Margin="0"/>
    
        </Grid>
    </Window>
    

    CS:

    private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var _bigDataPoints = new List<DataPoint>();
    
            // #x1 double #y double
    
            _bigDataPoints.Add(new DataPoint(410.8070281, 4943000.0000000));
            _bigDataPoints.Add(new DataPoint(432.7935746, 5041000.0000000));
            _bigDataPoints.Add(new DataPoint(436.8319199, 5059000.0000000));
            _bigDataPoints.Add(new DataPoint(9918.193582, 47320000.0000000));
            _bigDataPoints.Add(new DataPoint(10099.91912, 48130000.0000000));
            _bigDataPoints.Add(new DataPoint(10216.58243, 48650000.0000000));
            _bigDataPoints.Add(new DataPoint(104904.5616, 470700000.0000000));
            _bigDataPoints.Add(new DataPoint(107282.6983, 481300000.0000000));
            _bigDataPoints.Add(new DataPoint(108337.1551, 486000000.0000000));
            _bigDataPoints.Add(new DataPoint(991388.6853, 4422000128.0000000));
            _bigDataPoints.Add(new DataPoint(1000362.786, 4462000128.0000000));
            _bigDataPoints.Add(new DataPoint(1006195.923, 4488000000));
    
            var logAxisX = new LogarithmicAxis() { Position = AxisPosition.Bottom, Title = "Log(x)", UseSuperExponentialFormat = false, Base = 10 };
            var linearAxisY = new LinearAxis() { Position = AxisPosition.Left, Title = "Y", UseSuperExponentialFormat = false };
    
            PlotModel ChartPlot = new PlotModel(); //-> this is property that is binding to oxyplot control
    
            ChartPlot.Axes.Add(linearAxisY);
            ChartPlot.Axes.Add(logAxisX);
    
            var lineSeriesBigData = new OxyPlot.Series.LineSeries();
            lineSeriesBigData.Points.AddRange(_bigDataPoints);
    
            ChartPlot.Series.Clear();
            ChartPlot.Annotations.Clear();
            ChartPlot.Series.Add(lineSeriesBigData);
    
            // This is the line you're missing
            plotView1.Model = ChartPlot;
        }
    

    enter image description here

  • 1

    该错误与PlotType属性有关

    不要使用笛卡儿!

相关问题