views:

422

answers:

1

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>
+1  A: 

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 the IsMarginVisible set to false to prevent the margin on the left and the right. Hopefully that will work for you.

DougJones