This project has moved and is read-only. For the latest updates, please go here.

how to set transparent backgroud in simple chart extension

Topics: SharpMap v2.0, WinForms Controls
Nov 3, 2010 at 7:21 AM

I used the SimpleChart extension (  in my winform application, but I find my pie always has a white backgroud unless I draw it pie directly using GDI+,


how can I have the same pie as the example illustration (




Nov 3, 2010 at 8:58 AM

hello flyinrain,

have you tried to change the end of the GetChart(int numMale, int numFemale) method to

        Bitmap r = (Bitmap)zgc.GetImage();
        return r;

Hth FObermaier

Nov 3, 2010 at 2:06 PM

Thanks FObermaier,

I used your codes as below :


        SharpMap.Rendering.Thematics.CustomTheme lliTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetChartingStyle);
        layCountriesPoint.Theme = lliTheme;


        public static  SharpMap.Styles.VectorStyle GetChartingStyle(SharpMap.Data.FeatureDataRow row)
            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();

            //int numMale = int.Parse(row["male"].ToString());
            //int numFemale = int.Parse(row["female"].ToString());

            int numMale = 50;
            int numFemale = 20;

            style.Symbol = GetChart(numMale, numFemale);

            return style;

       public static System.Drawing.Bitmap GetChart(int numMale, int numFemale)
            ZedGraphControl zgc = new ZedGraphControl();
            GraphPane myPane = zgc.GraphPane;  //  new GraphPane();

            zgc.Size = new Size(150, 150);

            myPane.Title.IsVisible = false;  // no title
            myPane.Border.IsVisible = false; // no border
            myPane.Chart.Border.IsVisible = false; // no border around the chart
            myPane.XAxis.IsVisible = false;  // no x-axis
            myPane.YAxis.IsVisible = false;  // no y-axis
            myPane.Legend.IsVisible = false; // no legend

            myPane.Chart.Fill.Type = FillType.None;
            myPane.Fill.Type = FillType.None;

            /* Pie Chart */
            // Add pie slices
            PieItem segment8 = myPane.AddPieSlice(numMale, Color.Green, Color.White, 45f, 0, "Male");
            PieItem segment9 = myPane.AddPieSlice(numFemale, Color.Red, Color.White, 45f, 0.2, "Female");

            //Hides the slice labels
            PieItem.Default.LabelType = PieLabelType.None;


            Bitmap r = (Bitmap)zgc.GetImage();
            r.MakeTransparent(r.GetPixel(0, 0));
            return r;

            //return (Bitmap)zgc.GetImage();


but the result did not change, any other tips ? thank  very much


Nov 3, 2010 at 2:15 PM

sorry , my mistake, the below code is okay now:



thanks again.