Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1062
  • Last Modified:

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
0
mwskuzzy
Asked:
mwskuzzy
  • 2
1 Solution
 
Rory ArchibaldCommented:
Hi,
Try using:
 

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

Open in new window

0
 
mwskuzzyAuthor Commented:
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?
0
 
Rory ArchibaldCommented:
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now