ASP.Net MS Chart Control 饼图:删除不需要的填充

发布于 2024-09-05 07:16:23 字数 1242 浏览 6 评论 0原文

您好,

我正在尝试使用 MS Chart 控件创建简单的饼图。当我的饼图在浏览器中呈现时,我在饼图周围填充了我无法摆脱的内容。我希望饼图紧靠图像边缘,没有填充或边距。关于如何实现这一目标有什么想法吗?

在我下面的代码中,填充以蓝色突出显示。即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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深陷 2024-09-12 07:16:23

我对饼图不是特别熟悉,但对于折线图,需要在 ChartArea 内设置位置:

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

我相信这将图表区域设置为从左上角开始并占据图表的整个区域(100%)。那么就需要IsMarginVisible = false来防止左右边距。希望这对你有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文