如何在 Oxyplot 列图中设置条形的宽度?

Posted

技术标签:

【中文标题】如何在 Oxyplot 列图中设置条形的宽度?【英文标题】:How do I set the width of the bars in an Oxyplot column plot? 【发布时间】: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>

【问题讨论】:

另见this explanation by VisualMelon。 【参考方案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 的子类,但没有任何改变。你能看到我的问题吗:***.com/questions/69998490/oxyplot-bar-width @user979331 - 当然你必须使用你的子类。在您当前使用new ColumnSeries 的地方,您改为使用new MyColumnSeries。否则,将继续执行现有的 ColumnSeries 代码。这是基本的 OO 原则。

以上是关于如何在 Oxyplot 列图中设置条形的宽度?的主要内容,如果未能解决你的问题,请参考以下文章

减少 svg 图中条形之间的间隙

如何使用 Oxyplot 创建方形绘图区域

如何在 matplotlib 条形图中用希腊符号替换主轴和次轴的图例标签?

如何在 matplotlib pandas 的一张图中组合两个文件的两个条形图

在 MPAndroidChart 条形图中为条形设置不同的颜色

如何使用 React Faux DOM 在 D3 分组条形图中呈现矩形?