gpt4 book ai didi

WPF 和 Oxyplot : graph with CategoryAxis and LogarithmicAxis

转载 作者:行者123 更新时间:2023-12-02 01:38:00 26 4
gpt4 key购买 nike

我目前正在使用 Oxyplot 和演示示例(可以在那里下载 https://github.com/oxyplot/oxyplot/archive/develop.zip ),更具体地说是示例“ColumnSeriesDemo”。

这是执行时的样子:

before

代码:

public MainWindow()
{
this.InitializeComponent();

// Create some data
this.Items = new Collection<Item>
{
new Item {Label = "Apples", Value1 = 37, Value2 = 12, Value3 = 19},
new Item {Label = "Pears", Value1 = 7, Value2 = 21, Value3 = 9},
new Item {Label = "Bananas", Value1 = 23, Value2 = 2, Value3 = 29}
};

// Create the plot model
var tmp = new PlotModel { Title = "Column series", LegendPlacement = LegendPlacement.Outside, LegendPosition = LegendPosition.RightTop, LegendOrientation = LegendOrientation.Vertical };

// Add the axes, note that MinimumPadding and AbsoluteMinimum should be set on the value axis.
tmp.Axes.Add(new CategoryAxis { ItemsSource = this.Items, LabelField = "Label" });
tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });

// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
tmp.Series.Add(new ColumnSeries { Title = "2009", ItemsSource = this.Items, ValueField = "Value1" });
tmp.Series.Add(new ColumnSeries { Title = "2010", ItemsSource = this.Items, ValueField = "Value2" });
tmp.Series.Add(new ColumnSeries { Title = "2011", ItemsSource = this.Items, ValueField = "Value3" });

this.Model1 = tmp;

this.DataContext = this;
}

我想要一个对数 Y 轴。

在上面的代码中,我更改了第二个轴声明

tmp.Axes.Add(new LinearAxis { Position = AxisPosition.Left, MinimumPadding = 0, AbsoluteMinimum = 0 });

tmp.Axes.Add(new LogarithmicAxis { MinorTickSize = 0, Minimum = 1, Maximum = 35, Title = "Log Axis", Position = AxisPosition.Left, Base = 10, TickStyle = TickStyle.Outside });

但是执行代码时,结果如下:

after

据我了解,彩色部分应该是空白的,空白部分应该是彩色的。请问我缺少什么?

最佳答案

我遇到了同样的问题,我花了几个小时才找到可以解决问题的神奇属性,它的名字是.....BaseValue!它是 ColumnSeries 的一个属性,因此在上面的代码中,需要更改的只是创建 ColumnSeries 的位:

// Add the series, note that the BarSeries are using the same ItemsSource as the CategoryAxis.
tmp.Series.Add(new ColumnSeries { BaseValue = 1, Title = "2009", ItemsSource = this.Items, ValueField = "Value1" });
tmp.Series.Add(new ColumnSeries { BaseValue = 1, Title = "2010", ItemsSource = this.Items, ValueField = "Value2" });
tmp.Series.Add(new ColumnSeries { BaseValue = 1, Title = "2011", ItemsSource = this.Items, ValueField = "Value3" });

我还没有测试问题中的代码,但我很确定这会起作用。

干杯!

关于WPF 和 Oxyplot : graph with CategoryAxis and LogarithmicAxis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33958195/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com