4

I'm trying to get a pie chart to display as transparent. Ideally it should look like the 3rd chart from the left on this page (link).

So far I've tried setting the transparency on the chartArea:

<asp:ChartArea Name="ChartArea1" BackColor="64, 165, 191, 228" BackGradientStyle="TopBottom" 
            BackSecondaryColor="Transparent" BorderColor="64, 64, 64, 64"  
            ShadowColor="Transparent">

Also I tried setting it from codebehind:

    protected void pieChart_Customize(object sender, EventArgs e)
    {
        foreach (Series s in pieChart.Series)
        {
            s.Color = Color.FromArgb(128, s.Color);
        }
    }

However neither of these approaches work. Has anybody managed to set the transparency on this type of chart control?

Dr. Greenthumb
  • 2,280
  • 5
  • 27
  • 33

4 Answers4

3

This seems to work:

protected void Button1_Click(object sender, EventArgs e)
{
    Chart1.Series[0].Points[0].Color = Color.FromArgb(100, Color.Blue);
}

Reference: http://msdn.microsoft.com/en-us/library/1hstcth9%28v=vs.110%29.aspx

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • This code is giving me an ArgumentOutOfRangeException. I tried debugging it and the 'points' parameter is 0 for the pie chart, even though it has 11 partitions. I recall using similar code for my bar charts and it was working. Maybe pie charts require different approach? – Dr. Greenthumb Apr 11 '11 at 09:14
2

I found the answer on the MSDN site: link

Here's the exact code that ended up working for me:

    protected void Page_Load(object sender, EventArgs e)
    {
        pieChart.Series[0].Palette = ChartColorPalette.SemiTransparent;
    }
Dr. Greenthumb
  • 2,280
  • 5
  • 27
  • 33
2

The only way to get the same color is to use default palette and set alpha for all points to be 220 (this is the number they use in all samples):

Use this code to get the desirable effect after you set all the points:

myChart.ApplyPaletteColors();

foreach (var series in myChart.Series)
{
    foreach (var point in series.Points)
    {
        point.Color = Color.FromArgb(220, point.Color);
    }
}
Oleg Sakharov
  • 1,127
  • 2
  • 20
  • 19
-1

Thank you !! cause I had the same problem. now I fixed my app and It is working now!! I use:

myChart.ApplyPaletteColors();

foreach (var series in myChart.Series)
{
    foreach (var point in series.Points)
    {
        point.Color = Color.FromArgb(220, point.Color);
    }
}

Quoted Heading

Thank you!! :)

khr055
  • 28,690
  • 16
  • 36
  • 48
Ken
  • 1