PdfSharpCore icon indicating copy to clipboard operation
PdfSharpCore copied to clipboard

Setting orientation on vertical X Axis title in bar chart is ignored

Open Prologh opened this issue 3 years ago • 0 comments

Hi!

I'm trying to rotate the vertical X axis in a bar chart so it rotated 90 degrees counter clockwise like in this column chart:

image

For column chart it works flawlessy, but for bar chart, the whole orientation setting is ignored and leaves me with this:

image

Looking at the VerticalYAxisRenderer code I belive it is because a AxisTitleRenderer is used to render the AxisTitle for column chart and a plain string is drawn in bar chart in VerticalXAxisRenderer. So, the logic is already there, it just needs to be reused in VerticalXAxisRenderer.

My code for bar chart:

var chart = new Chart
{
    Left = 0,
    Type = ChartType.Bar2D,
    Width = Unit.FromCentimeter(16),
    Height = Unit.FromCentimeter(12),
};
var series = chart.SeriesCollection.AddSeries();
series.Name = "Series 1";
series.Add(new double[] { 1, 5, -3, 20, 11 });

series = chart.SeriesCollection.AddSeries();
series.Name = "Series 2";
series.Add(new double[] { 22, 4, 12, 8, 12 });

var xseries = chart.XValues.AddXSeries();
xseries.Add(new string[] { "foo", "bar", "rgb", "up", "down" });

chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.XAxis.Title.Caption = "X-Axis";
chart.XAxis.Title.Orientation = 90;
chart.XAxis.Title.VerticalAlignment = VerticalAlignment.Center;

chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.YAxis.Title.Caption = "Y-Axis";
chart.YAxis.Title.Alignment = HorizontalAlignment.Center;

chart.PlotArea.LineFormat.Color = Colors.DarkGray;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;

chart.RightArea.AddLegend();

chart.DataLabel.Type = DataLabelType.Value;
chart.DataLabel.Position = DataLabelPosition.InsideEnd;

Almost the same code for column chart:

var chart = new Chart
{
    Left = 0,
    Type = ChartType.Column2D,
    Width = Unit.FromCentimeter(16),
    Height = Unit.FromCentimeter(12),
};
var series = chart.SeriesCollection.AddSeries();
series.Name = "Series 1";
series.Add(new double[] { 1, 5, -3, 20, 11 });

series = chart.SeriesCollection.AddSeries();
series.Name = "Series 2";
series.Add(new double[] { 22, 4, 12, 8, 12 });

var xseries = chart.XValues.AddXSeries();
xseries.Add(new string[] { "foo", "bar", "rgb", "up", "down" });

chart.XAxis.MajorTickMark = TickMarkType.Outside;
chart.XAxis.Title.Caption = "X-Axis";
chart.XAxis.Title.Alignment = HorizontalAlignment.Center;

chart.YAxis.MajorTickMark = TickMarkType.Outside;
chart.YAxis.HasMajorGridlines = true;
chart.YAxis.Title.Caption = "Y-Axis";
chart.YAxis.Title.VerticalAlignment = VerticalAlignment.Center;
chart.YAxis.Title.Orientation = 90;

chart.PlotArea.LineFormat.Color = Colors.DarkGray;
chart.PlotArea.LineFormat.Width = 1;
chart.PlotArea.LineFormat.Visible = true;

chart.RightArea.AddLegend();

chart.DataLabel.Type = DataLabelType.Value;
chart.DataLabel.Position = DataLabelPosition.InsideEnd;

Prologh avatar May 14 '21 06:05 Prologh