programatically change chart

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using powerpoint to programatically create slides displaying MS GRaph Charts.
I am using .NET and C#.

I am having trouble location help for this topic.

My questions are:

1. I want to programatically change the direction of the Category Axis. I wish to rotate them so they are upright instead of on their side. How can I do this?
objCatAxis.TickLabels.Orientation = Graph.XlTicklabelOrientationUpWard does not seem to be working.


2. I am having trouble defining colors for my charts. It seems to be happening automatically. I want to control which colors get displayed. I wish to do this programatically as well. Can you help?

objSeries.Fill.BackColor.SchemeColor = iColor
objSeries.Fill.ForeColor.SchemeColor = iColor

does not seem to work.


Thanks,

jmv
 
1. Try this instead:

objCatAxis.ReversePlotOrder = True

2. These look like they should work. What value does iColor take? Also,
since you're making the forecolor and backcolor of the fill pattern the
same, why not just use

objSeries.Interior.ColorIndex = iColor

(I checked these in Excel. Most of the MSChart OM is like Excel's, just
watered down.)

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Jeanne -

Sorry, I misread your post. ReversePlotOrder is what reversed the order
of your data.

Instead of xlticklabelorientationupward, try using the numerical value
of the constant, which is -4171. If the references aren't set properly,
the code might think it's an uninitialized variable, and just use the
default.

Ha, now the colors. PowerPoint has a color scheme, which uses certain
colors for certain things in the slide show. Some of these colors then
get used in MSGraph. MSGraph has a color palette, 56 colors that can be
used in its charts, some by default, some based on PowerPoint's color
scheme. The constants you display may be from a default palette, or from
someone's customized palette. Excel also has a 56-color palette, and
each workbook has a distinct palette, which may be the default, or may
have been customized.

MSGraph ("MSGrump" to those more familiar with it) is a royal PITA to
program. Documentation is scarce, examples few and far between, and you
have to break into the OLE Object to even begin to program it. Most
chart programmers, including the PowerPoint people, do their charting in
Excel. You're using C#, so programming for Excel is no worse than
programming for PowerPoint (in private I even say "better than"). And
examples abound: Google for Excel PowerPoint VBA to get started. Also
check my web site.

To get the Excel charts into PowerPoint, you can follow several paths.
My favorite is to copy the charts as pictures in Excel, and paste the
pictures into PowerPoint. You can paste link, although PowerPoint didn't
have PasteSpecial-Link in its VBA object model until 2003. You can
copy-paste the chart itself, but this copies the entire workbook into
the OLE container, jeopardizing the security of the data and bloating
the presentation. A best practices approach, which I'm just now
mastering thanks to PPT MVP Brian Reilly, is to save the chart and its
data in its own workbook, with the chart on its own chart sheet, sized
to its final configuration by adjusting the margins in Page Setup; from
PowerPoint, use the Slide.AddOLEObject to insert the file. If you want
it linked, link the data in the small workbook to the original data in
the original workbook. Links are problematic, though, because someone
will always lose the workbook or save it in the wrong directory, then
blame you because it doesn't work.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
I just can't seem to control the colors. I need to get this to work ASAP!

objSeries.Interior.ColorIndex = iColor

gives me an error so I must use

objSeries.Fill.BackColor.SchemeColor = iColor
objSeries.Fill.ForeColor.SchemeColor = iColor

I am getting my iColor from the color pallette in the vbagr10 HTML help file. However they do not seem to be displaying correctly. It appears as if ppt is using anycolor it wants.

I need about 20 different colors can you please help me figure out how to code this?

I am not able to meet my user requirements without this.

Thanks!
 
Jeanne -

Colors, yes, that'll frustrate anyone. Both MSGraph and Excel use 56
color palettes, and certain of them are the default colors for a chart.
But some of MSG's colors are dictated by the color scheme in PowerPoint,
as I described in the previous post. You have to choose colors that are
not among the ones PowerPoint dictates.

To see which color comes from where in the palette (they go in order the
way your keyboard is laid out in order: some are aligned, but the
majority have been moved for one reason or other), record a macro while
you format a chart in Excel using a color in the same position in the
palette. Charts usually use the bottom two rows of the palette for
default colors, and somewhere down there is where PowerPoint stakes a
claim, so you should use other colors.

You didn't say why you aren't using Excel for the charts. It would be an
awful lot easier, since you can more readily query the object model and
you can record code to check your syntax.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
I am not using excel mainly because I do not really know what you mean by using it.

My requirement is this:

Within a Web Application (c# project) allow a user to generate a OWC11.Chart, an OWC11.Spreadsheet both that display on the page and also have this function generate a ppt slide that is saved to the server.

I have created a separate project to generate the pptslide. It works for the most part. There were a lot of security issues to overcome based on the fact that we needed PPT and Graph to run as a single user identity on the server.

Also C# examples are hard to come by and it was difficult for me to get at the ppt and chart properties the way I expected. I open up ppt, open a presenation, add a slide, generate the slide using a datasheet, then close the file.

To add Excel to the mix I am not sure how or why I would do that and even if it fits into my solution. I have spent too much time on this problem already.

But if you can explain the benefits (and maybe how to do this) I could work it into my solution somehow.

Do I need to start excel, build it there, open ppt etc. and open the ecel file in ppt?
I just don't get it. And remember I have to do this all programatically in code.

Thanks for your ongoing help and advice.

Regards,

jmv
 
My point about using Excel had multiple facets. First, since you already
are automating PowerPoint and MS Graph within that, I didn't think it
would be any more complicated to automate PowerPoint and Excel instead.

Using Excel over MS Graph has several advantages. In Excel, you can
record a macro to help with syntax (no, it isn't perfect!), while MS
Graph seems to operate in a vacuum as far as PowerPoint's macro recorder
is concerned. When automating MS Graph, I always feel handicapped by not
really being able to sense what I'm doing. Excel's object model seems
more accessible, because I can try out one liners in the Immediate
window and watch the results in the worksheet. Excel offers more
flexibility in terms of chart types, combination charts, and the effects
such combination charts can provide. Also, there are many more examples
throughout the web and newsgroups for Excel than for MS Graph.

Granted doing this from C# adds a layer of smog to the process, but you
might try more googling with different combinations of keywords. There
must be a few MS Knowledge Base articles and MSDN pages showing how to
use C# with Office, and once you have a few examples, you should be able
to figure out how to do what you need.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
I need a jump start...

Can you possibly give me some c# code to try in my page? Just something quick. create the graph and apply a series? That would be MOST helpful. Then I can go from there (I hope).

Thanks,

jmv
 
I don't know any C#, but I typed this into a google search:

c++ c# excel chart

and the first link up was this, which contained a couple long juicy
procedures:

Microsoft Knowledge Base Article - 302084
How To Automate Microsoft Excel from Microsoft Visual C#.NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;302084

There were at least a few other links which might be relevant, and one
or two might point to a site you'll want to bookmark.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services
Tutorials and Custom Solutions
http://PeltierTech.com/
_______
 
Back
Top