ASP.Net MS Chart Control Pie Chart: remove unwanted padding

HI

im trying to create simple pie chart using the MS Chart controls. When my pie chart gets rendered in the browser i get padding around the pie chart that i cant get rid of. i would like the pie chart to sit up against the edge of the image with no padding or margin. Any ideas on how i can achieve this?

in my code below the padding is highlighted in blue. i.e Chart1.BackColor = System.Drawing.Color.Blue;

 <script type="text/C#" runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            //Set the chart type
            Chart1.Series["Series1"].ChartType = SeriesChartType.Pie;

            //add points
            Chart1.Series["Series1"].Points.AddY(12);
            Chart1.Series["Series1"].Points.AddY(45);
            Chart1.Series["Series1"].Points.AddY(67);

            //set back color of chart object
            Chart1.BackColor = System.Drawing.Color.Blue;

            //set back color of chart area
            Chart1.ChartAreas["ChartArea1"].BackColor = System.Drawing.Color.Green;

        }
    </script>

    <asp:Chart ID="Chart1" runat="server">
        <Series>
            <asp:Series Name="Series1" ChartType="Pie">
            </asp:Series>
        </Series>
        <ChartAreas>
            <asp:ChartArea Name="ChartArea1">
            </asp:ChartArea>
        </ChartAreas>
    </asp:Chart>

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I’m not specifically familiar with the Pie chart, but for a line chart the Position needs to be set within the ChartArea:

<ChartArea Name="ChartArea1" BackColor="Transparent" BorderWidth="0" >
      <AxisX LineWidth="0" IsMarginVisible="False">
      </AxisX>
      <Position Height="100" Width="100" X="0" Y="0" />
    </ChartArea>

That sets the chart area to start at the top left corner, I believe and take up the entire area of the chart (100% of it). Then you need IsMarginVisible = false to prevent the margin on the left and the right. Hopefully that will work for you.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x