how to superimpose chart images or extract data by vba

J

Jon Peltier

Here's part 2:

Macro to extract data from a chart in Excel
http://support.microsoft.com/kb/300643

Part 1 may be satisfied by creating a combination chart. What types of
chart are you trying to superimpose?

Actually superimposing one chart on another, requires you to equalize
the left and top positions and the width and height dimensions of the
two chart objects. You may also need to equalize these parameters for
the plot areas as well.

''''''''''''''''''''''''''''''' snippet

Dim cht1 As ChartObject
Dim cht2 As ChartObject

Set cht1 = ActiveSheet.ChartObjects(1)
Set cht2 = ActiveSheet.ChartObjects(2)

' equalize chart size and position
cht2.Left = cht1.Left
cht2.Top = cht1.Top
cht2.Width = cht1.Width
cht2.Height= cht1.Height

' temporarily shrink plot area
cht2.Chart.PlotArea.Width = cht2.Chart.PlotArea.Width / 2
cht2.Chart.PlotArea.Height= cht2.Chart.PlotArea.Height / 2

' equalize plot area size and position
cht2.Chart.PlotArea.Left = cht1.Chart.PlotArea.Left
cht2.Chart.PlotArea.Top = cht1.Chart.PlotArea.Top
cht2.Chart.PlotArea.Width = cht1.Chart.PlotArea.Width
cht2.Chart.PlotArea.Height= cht1.Chart.PlotArea.Height

''''''''''''''''''''''''''''''' end snippet

Long ago I posted a small utility to do this on my web site:

Align Excel Charts Using VBA
http://peltiertech.com/Excel/Charts/AlignCharts.html

- Jon
 
J

Jon Peltier

If you are dealing with static images, then my suggestions will be of no
use. You can superimpose the two images, but if they are not the same
size, nor scaled the same, and if they don't have transparent
backgrounds, you will not gain anything from this exercise.

- Jon
 
D

Davyboom

thanks to Jon,

Actually my problem is to call out the yield curve (line graph) from the
same web but for different date. Thus both images have the same axis. The
easiest way for immedaite comparison is to superimpose both, get the top
peice of transparent abckground (here is the problem I cannot manage). If I
can extract data from the graph by VBA, so much the better. I can then do
deeper analysis.

as for your macro. I shall try on that this week-end.
 
J

Jon Peltier

Remember: the macros I posted will work on charts.

You might be able to save the image as a GIF or PNG, open it in an image
editor (I like IrfanVIEW), and save it with white as the transparent color.

- Jon
 
D

Davyboom

thanks to Jon

I shall try on that.

Jon Peltier said:
Remember: the macros I posted will work on charts.

You might be able to save the image as a GIF or PNG, open it in an image
editor (I like IrfanVIEW), and save it with white as the transparent color.

- Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top