Better explanation for Chart.ChartWizard

Posted on 2008-11-07
Last Modified: 2013-12-17
Hi All
I'm dying here. I am trying to create an excel chart programatically. I can easily create the chart using c# but the chart displays the category in the values axis and the values in the category axis. I have tried to find proper explanations of the Chart.ChartWizard method on MSDN but there are no examples and the parameter descriptions make no sense. I have attached a screen shot of the report I need to chart. The "PercentageThanSmoke" column is the categories (%) and the Count column is the series values.

Here is the code snippet I am using:

            // Create the chart
            ChartObjects charts = ( ChartObjects )worksheet.ChartObjects( Missing.Value );
            ChartObject chart = charts.Add( 0, ( int )( double )range.Height, 600, 400 );
            Range chartRange = worksheet.get_Range( "A3", string.Format( "B{0}", rows + 2 ) );
            chart.Chart.ChartWizard( chartRange, XlChartType.xl3DColumn, 1, XlRowCol.xlColumns, 0, 0, false, "Percentage That Smoke", "Category", "Values", "" );
            chart.Chart.HasLegend = false;
            chart.Chart.HasDataTable = false;
            chart.Chart.ApplyDataLabels( XlDataLabelsType.xlDataLabelsShowValue, false, false, false, false, false, false, false, false, Missing.Value );
            chart.Name = ParseColumnName( reportName );
            chart.Shadow = true;

I am sure it has something do do with the "PlotBy" paramater and the "CategoryLabels" and "SeriesLabels" parameters. I have tried to change the values but still nothing.

Any urgent help would be greatly appreciated.

Question by:mwskuzzy
    LVL 85

    Expert Comment

    by:Rory Archibald
    Try using:

    chart.Chart.ChartWizard( chartRange, XlChartType.xl3DColumn, 1, XlRowCol.xlColumns, 1, 0, false, "Percentage That Smoke", "Category", "Values", "" );

    Open in new window


    Author Comment

    Hi rorya

    I have tried that but still got the same results. I am currently playing around with the "Axis" object to see if i can manually set the category and series axis. I am sure however that specifying the XLRowCol as xlColumns should read the report this way. I also noticed that even if i specify the range as only including two columns (PercentageThatSmoke and Count) the chart still plots all three columns?
    LVL 85

    Accepted Solution

    That's odd - it works from within Excel (I don't have C# here to test). To do it manually, you would use the chart's SeriesCollection collection (which contains Series objects) and set the XValues to the category label range.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
    Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now