Link to home
Start Free TrialLog in
Avatar of mwskuzzy
mwskuzzy

asked on

Better explanation for Chart.ChartWizard

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.

Thanks
Sheet1.xls
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi,
Try using:
 

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

Open in new window

Avatar of mwskuzzy
mwskuzzy

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial