问题
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