【问题标题】:How do I set the width of the bars in an Oxyplot column plot?如何在 Oxyplot 列图中设置条形的宽度?
【发布时间】:2018-10-31 09:11:40
【问题描述】:

我正在尝试设置列系列中条形的宽度,但在 ColumnSeries 上设置 ColumnWidth 无效。如何影响列的宽度?

<oxy:Plot>
    <oxy:Plot.Series>
        <oxy:ColumnSeries ColumnWidth="1000" />
    </oxy:Plot.Series>
    <oxy:Plot.Axes>
        <oxy:CategoryAxis Key="CategoryAxis" />
        <oxy:LinearAxis  />
    </oxy:Plot.Axes>
</oxy:Plot>

【问题讨论】:

标签: wpf xaml oxyplot


【解决方案1】:

查看OxyPlot source,我们可以看到实际的条形宽度计算如下。你应该可以通过调整GapWidthMaxWidth 来达到你想要的效果。

protected override double GetActualBarWidth()
{
    var categoryAxis = this.GetCategoryAxis();
    return this.ColumnWidth / (1 + categoryAxis.GapWidth) / categoryAxis.MaxWidth;
}

【讨论】:

  • 如果由于某种原因您需要更多控制权,看起来您可以创建一个子类:public class MyColumnSeries : ColumnSeries { ... protected override double GetActualBarWidth() { ...any-code-you-want... } ... }
  • @ToolmakerSteve 我只是尝试创建 ColumnSeries 的子类,但没有任何改变。你能看到我的问题吗:stackoverflow.com/questions/69998490/oxyplot-bar-width
  • @user979331 - 当然你必须使用你的子类。在您当前使用new ColumnSeries 的地方,您改为使用new MyColumnSeries。否则,将继续执行现有的 ColumnSeries 代码。这是基本的 OO 原则。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
相关资源
最近更新 更多