PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

How do I add number labels as percentages to a column chart?
http://forum.pdfsharp.de/viewtopic.php?f=2&t=2344
Page 1 of 1

Author:  Kevin [ Fri Mar 01, 2013 9:49 pm ]
Post subject:  How do I add number labels as percentages to a column chart?

I'm adding a chart to a MigraDoc Document:

Code:
            Chart chart = new Chart();
            chart.Left = 0;

            chart.Width = Unit.FromCentimeter(16);
            chart.Height = Unit.FromCentimeter(12);
            Series series = chart.SeriesCollection.AddSeries();
            series.ChartType = ChartType.Column2D;
            series.Add(0.13, 0.01, 0.49, 0.10, 0.57, 0.19);
            series.HasDataLabel = true;

            XSeries xseries = chart.XValues.AddXSeries();
            xseries.Add(/* some strings */);

            chart.XAxis.MajorTickMark = TickMarkType.Outside;
            chart.YAxis.MajorTickMark = TickMarkType.Outside;
            chart.YAxis.HasMajorGridlines = true;

            section.Add(chart);


I would like to have the data labels and y-axis labels on the chart formatted as percents. I attached a picture of what I want to see.

How do I:
1) Format the data labels as percents?
2) Format the y-axis labels as percents?
3) Move the data labels on top of the columns instead of inside of them?

Attachments:
chart_with_percents.png
chart_with_percents.png [ 14.15 KiB | Viewed 5454 times ]

Author:  Kevin [ Mon Mar 04, 2013 8:23 pm ]
Post subject:  Re: How do I add number labels as percentages to a column ch

This code solved my problem:

Code:
series.DataLabel.Format = "#0.0%";
series.DataLabel.Position = DataLabelPosition.OutsideEnd;

//snip...

chart.YAxis.TickLabels.Format = "#0%";


I'm not sure, but it looked like the format of the Strings used for Format properties throughout MigraDoc follow the rules described here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/