How to increase the drawing area for an Axis in Oxyplot?

穿精又带淫゛_ 提交于 2020-01-05 06:54:18

问题


I'm writing a utility to email a stacked column chart which displays tasks for each person. Right now I'm using PngExporter in OxyPlot.WindowsForms to export the plot but I can't seem to figure out how to control the lower bounds of the image. The usernames can be quite long and will spill outside and I would like to extend the drawing area for the bottom axis so that all of the names will be visible.

Here's what it looks like right now

And here's the code for what I have so far

        var plot = new PlotModel()
        {
            Title = "Mantis Report"
        };

        // CATEGORY AXIS CODE====================================
        var categoryaxis = new CategoryAxis();
        foreach (var e in employees)
            categoryaxis.ActualLabels.Add(paddedString("Jebediah Kerman"));
        categoryaxis.Angle = 30;

        categoryaxis.AxisTickToLabelDistance = 10;
        // CATEGORY AXIS CODE====================================

        plot.Axes.Add(categoryaxis);
        plot.Axes.Add(new LinearAxis());

        var series = new ColumnSeries();
        series.IsStacked = true;

        int employeeindex = 0;
        foreach (var employee in employees)
        {
            foreach (var entry in employee.Tasks)
            {
                series.Items.Add(new ColumnItem(entry.Value, employeeindex) { Color = colors[entry.Key] });
            }
            employeeindex++;
        }

        plot.Series.Add(series);

        plot.LegendTitle = "legend";
        plot.LegendPlacement = LegendPlacement.Outside;
        foreach (string task in tasktypes)
        {
            var newseries = new ColumnSeries()
            {
                FillColor = colors[task]
                , Title = task
            };
            plot.Series.Add(newseries);
        }

paddedString() prepends the given string's length in whitespace and returns it. This is my current approach to "translating" the label but right now I'm worrying about drawing the rest of the name.

I've looked through the CategoryAxis page but I can't seem to find a way to extend the axis area so that the names will be completely displayed. And no, I would prefer not to just shorten the usernames.


回答1:


This worked for me in a WPF application.

var currentMargins = plotModel.PlotMargins;
plotModel.PlotMargins = new OxyThickness(currentMargins.Left, currentMargins.Top, currentMargins.Right, 100);


来源:https://stackoverflow.com/questions/24638301/how-to-increase-the-drawing-area-for-an-axis-in-oxyplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!