Microsoft图表控件无法设置背景透明

发布于 2024-12-11 01:12:09 字数 1839 浏览 0 评论 0原文

我有一个微软饼图控件。我将背景设置为透明,但它保持白色。正如您所看到的,我已经设置了 BorderSkin 的 BackColor 和 PageColor 属性。我还设置了 ChartArea 的 BackColor。这是一些代码。

Chart chart = new Chart
            {
                Width = 190,
                Height = 159,
                RenderType = RenderType.BinaryStreaming,
                AntiAliasing = AntiAliasingStyles.Graphics,
                TextAntiAliasingQuality = TextAntiAliasingQuality.Normal
            };

            // turn on transparency
            chart.BorderSkin.BackColor = Color.Transparent;
            chart.BorderSkin.PageColor = Color.Transparent;
            chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;

            chart.ChartAreas.Add("");

            chart.ChartAreas[0].AxisX.Interval = 1; // setting this to 1 forces all items to show
            chart.ChartAreas[0].AxisX.LabelStyle.Enabled = true;
            chart.ChartAreas[0].AxisX.TitleFont = xLabelFont;
            chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;

            chart.ChartAreas[0].AxisY.TitleFont = yLabelFont;
            chart.ChartAreas[0].AxisY.LabelStyle.IsStaggered = false; // staggers axis label
            chart.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Horizontal;
            chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            chart.ChartAreas[0].AlignmentOrientation = AreaAlignmentOrientations.All;

            chart.ChartAreas[0].BackColor = Color.Transparent;
            chart.Series.Add("");
            chart.Series[0].ChartType = SeriesChartType.Pie;
            //chart.Series[0]["PieLabelStyle"] = "Disabled"; // disable labels
            chart.Series[0].IsValueShownAsLabel = true; // *** super important to be able to manually set labels show point labels for value ***

            chart.ChartAreas[0].Area3DStyle.Enable3D = true;

I have a microsoft pie chart control. I am setting the background transparent, but it is staying white. As you can see I've set the BackColor and PageColor properties of the BorderSkin. I've also set the BackColor of the ChartArea as well. Here's some code.

Chart chart = new Chart
            {
                Width = 190,
                Height = 159,
                RenderType = RenderType.BinaryStreaming,
                AntiAliasing = AntiAliasingStyles.Graphics,
                TextAntiAliasingQuality = TextAntiAliasingQuality.Normal
            };

            // turn on transparency
            chart.BorderSkin.BackColor = Color.Transparent;
            chart.BorderSkin.PageColor = Color.Transparent;
            chart.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;

            chart.ChartAreas.Add("");

            chart.ChartAreas[0].AxisX.Interval = 1; // setting this to 1 forces all items to show
            chart.ChartAreas[0].AxisX.LabelStyle.Enabled = true;
            chart.ChartAreas[0].AxisX.TitleFont = xLabelFont;
            chart.ChartAreas[0].AxisX.MajorGrid.Enabled = false;

            chart.ChartAreas[0].AxisY.TitleFont = yLabelFont;
            chart.ChartAreas[0].AxisY.LabelStyle.IsStaggered = false; // staggers axis label
            chart.ChartAreas[0].AxisY.TextOrientation = TextOrientation.Horizontal;
            chart.ChartAreas[0].AxisY.MajorGrid.Enabled = false;
            chart.ChartAreas[0].AlignmentOrientation = AreaAlignmentOrientations.All;

            chart.ChartAreas[0].BackColor = Color.Transparent;
            chart.Series.Add("");
            chart.Series[0].ChartType = SeriesChartType.Pie;
            //chart.Series[0]["PieLabelStyle"] = "Disabled"; // disable labels
            chart.Series[0].IsValueShownAsLabel = true; // *** super important to be able to manually set labels show point labels for value ***

            chart.ChartAreas[0].Area3DStyle.Enable3D = true;

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

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

发布评论

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

评论(3

久伴你 2024-12-18 01:12:09

我没有看到这一行:

chart.BackColor = Color.Transparent;

I don't see this line:

chart.BackColor = Color.Transparent;
请远离我 2024-12-18 01:12:09

图表、图表区域、图例等的颜色是单独设置的。
请记住添加:

chart.TextAntiAliasingQuality = TextAntiAliasingQuality.SystemDefault;

当您将图表的背景设置为透明时,否则您将得到可怕的低质量字体。

Colors of chart, chart's area(s), legends, etc... are set separately.
And remember add:

chart.TextAntiAliasingQuality = TextAntiAliasingQuality.SystemDefault;

when you set the background of the chart to transparent, or you will get terrible low quality fonts.

世态炎凉 2024-12-18 01:12:09

我需要这两行:

chart.BackColor = Color.Transparent;
chart.ChartAreas[0].BackColor = Color.Transparent;

I needed these two lines:

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