user583824
user583824

Reputation:

Microsoft chart control failing to set background transparent

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;

Upvotes: 2

Views: 2611

Answers (3)

W. Boldt
W. Boldt

Reputation: 11

I needed these two lines:

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

Upvotes: 1

cheny
cheny

Reputation: 2725

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.

Upvotes: 1

Steve Wellens
Steve Wellens

Reputation: 20620

I don't see this line:

chart.BackColor = Color.Transparent;

Upvotes: 1

Related Questions