Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8340743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:15:45+00:00 2026-06-09T05:15:45+00:00

I am drawing a pie chart with some data: private void DrawFractionChart(Excel.Worksheet activeSheet, Excel.ChartObjects

  • 0

I am drawing a pie chart with some data:

private void DrawFractionChart(Excel.Worksheet activeSheet, Excel.ChartObjects xlCharts, Excel.Range xRange, Excel.Range yRange)
{
        Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(200, 500, 200, 100);
        Excel.Chart chartPage = myChart.Chart;

        Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection();
        Excel.Series series1 = seriesCollection.NewSeries();
        series1.XValues = activeSheet.Range["E1","E3"];
        series1.Values = activeSheet.Range["F1","F3"];

        chartPage.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowPercent, true,true,false,true,true,true,true);
        chartPage.ChartType = Excel.XlChartType.xlDoughnut;

        Excel.Axis axis = chartPage.Axes(Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary) as Excel.Axis;
}

I just can’t figure out how to turn on data labels. I googled everywhere for it but nothing’s been helpful so far sadly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T05:15:46+00:00Added an answer on June 9, 2026 at 5:15 am

    Try this (TRIED AND TESTED)

        private void DrawFractionChart(Excel.Worksheet activeSheet, Excel.ChartObjects xlCharts, Excel.Range xRange, Excel.Range yRange)
        {
            Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(200, 500, 200, 100);
            Excel.Chart chartPage = myChart.Chart;
    
            Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection();
            Excel.Series series1 = seriesCollection.NewSeries();
            series1.XValues = activeSheet.Range["E1", "E3"];
            series1.Values = activeSheet.Range["F1", "F3"];
    
            chartPage.ChartType = Excel.XlChartType.xlDoughnut;
    
            Excel.Axis axis = chartPage.Axes(Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary) as Excel.Axis;
    
            series1.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowPercent, true, true, false, true, true, true, true);
        }
    

    One quick question though. If you are not using xRange and yRange then why declare it?

    This is the completed code that is tried and tested.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Excel = Microsoft.Office.Interop.Excel; 
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Microsoft.Office.Interop.Excel.Application xlexcel;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;
    
                object misValue = System.Reflection.Missing.Value;
                xlexcel = new Excel.Application();
    
                xlexcel.Visible = true;
                // Add a Workbook
                xlWorkBook = xlexcel.Workbooks.Add();
    
                // Set Sheet 1 as the sheet you want to work with
                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    
                xlWorkSheet.Cells[1, 5] = "Apples";
                xlWorkSheet.Cells[2, 5] = "Oranges";
                xlWorkSheet.Cells[3, 5] = "Pears";
    
                xlWorkSheet.Cells[1, 6] = "80";
                xlWorkSheet.Cells[2, 6] = "65";
                xlWorkSheet.Cells[3, 6] = "45";
    
                Excel.ChartObjects myCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
    
                // Specified xlWorkSheet.Cells[3, 6], xlWorkSheet.Cells[3, 6] just for the heck of it.
                DrawFractionChart(xlWorkSheet, myCharts, xlWorkSheet.Cells[3, 6], xlWorkSheet.Cells[3, 6]);
    
                //Once done close and quit Excel
                //xlWorkBook.Close(true, misValue, misValue);
                //xlexcel.Quit();
    
                //releaseObject(xlWorkSheet);
                //releaseObject(xlWorkBook);
                //releaseObject(xlexcel);
            }
    
            private void DrawFractionChart(Excel.Worksheet activeSheet, Excel.ChartObjects xlCharts, Excel.Range xRange, Excel.Range yRange)
            {
                Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(200, 500, 200, 100);
                Excel.Chart chartPage = myChart.Chart;
    
                Excel.SeriesCollection seriesCollection = chartPage.SeriesCollection();
                Excel.Series series1 = seriesCollection.NewSeries();
                series1.XValues = activeSheet.Range["E1", "E3"];
                series1.Values = activeSheet.Range["F1", "F3"];
    
                chartPage.ChartType = Excel.XlChartType.xlDoughnut;
    
                Excel.Axis axis = chartPage.Axes(Excel.XlAxisType.xlValue, Microsoft.Office.Interop.Excel.XlAxisGroup.xlPrimary) as Excel.Axis;
    
                series1.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowPercent, true, true, false, true, true, true, true);
            }
    
            //private void releaseObject(object obj)
            //{
            //    try
            //    {
            //        System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
            //        obj = null;
            //    }
            //    catch (Exception ex)
            //    {
            //        obj = null;
            //        MessageBox.Show("Unable to release the Object " + ex.ToString());
            //    }
            //    finally
            //    {
            //        GC.Collect();
            //    }
            //} 
        }
    }
    

    SNAPSHOT

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am drawing some pie charts using facet_wrap and coord_polar , let say I
I am using jqplot for drawing a pie chart. But when I draw a
I am drawing a pie chart using the CPTXYGraph in Core Plot. I have
Here I stuck with a problem in drawing the pie chart using coreplot in
I am drawing a pie chart, each slice has a different color. I need
I'm creating a simple pie chart with three data points. The first and second
One of the aspects of my app is drawing a pie chart. So once
I need to draw a pie chart. I found a nice tutorial here http://mac-objective-c.blogspot.com/2009/04/drawing-pie-charts.html
I've got a pie chart (example) with following fracs = [10, 20, 50, 30]
- (void)drawRect:(CGRect)rect { // Drawing code. stickerImage = [UIImage imageNamed:@betaImage.png]; CGSize size = stickerImage.size;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.