PC Review


Reply
Thread Tools Rate Thread

Creating a chart with VBA

 
 
=?Utf-8?B?SWFtSkQ=?=
Guest
Posts: n/a
 
      20th Nov 2006
I have created a chart that I would like to display with a line graph (or XY
Scatter). I use VBA to dynamically update the chart. I am using Excel 2000
and 2003.

The source data is stored in a user-defined variable which contains two
arrays. One is type "date" and the other is type "single".

The code will go through the spreadsheet populating the array with the
appropriate numbers.

I use the single type array for the y-values and the date type array for the
x-values. If I leave the chart as a line graph, it plots the chart fine with
one exception, the x-axis points are not spaced appropriately. If one point
is on 1/1/2006 and another is at 2/1/2006 they are they same distance apart
as if the two dates were 1/1/2006 and 6/1/2006. Basically, it doesn't
understand the difference between the dates, it just places the next one
right after the other.

I did some research and found that this is how it is for line graphs, so I
switched to XY Scatter plot as was suggested. Unfortuneately, the same thing
happens. It's just that instead of dates on the x-axis it shows just
incrementing numbers (1, 2, 3, etc....).

I know the values in the array are correct, because I looked at it as the
code was running. I think this has something to do with assigning the
XValues property of the chart to an array, but not 100% sure.

Any help possible would be appreciated.
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      21st Nov 2006
Well, I can't find any problems with the code you posted. And if you'd
applied a time scale to the line chart category axis you might have pulled
it off. Although there may also be a problem with the dates, if the XY chart
didn't recognize them as numeric.

Here are some pointers:

http://peltiertech.com/Excel/Charts/chartvba.html
http://peltiertech.com/Excel/ChartsH...ValueAxis.html

Why not dump the ranges into a worksheet and plot from these ranges. It
makes life much easier.

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


"IamJD" <(E-Mail Removed)> wrote in message
news:940388EE-7369-4416-BA03-(E-Mail Removed)...
>I have created a chart that I would like to display with a line graph (or
>XY
> Scatter). I use VBA to dynamically update the chart. I am using Excel
> 2000
> and 2003.
>
> The source data is stored in a user-defined variable which contains two
> arrays. One is type "date" and the other is type "single".
>
> The code will go through the spreadsheet populating the array with the
> appropriate numbers.
>
> I use the single type array for the y-values and the date type array for
> the
> x-values. If I leave the chart as a line graph, it plots the chart fine
> with
> one exception, the x-axis points are not spaced appropriately. If one
> point
> is on 1/1/2006 and another is at 2/1/2006 they are they same distance
> apart
> as if the two dates were 1/1/2006 and 6/1/2006. Basically, it doesn't
> understand the difference between the dates, it just places the next one
> right after the other.
>
> I did some research and found that this is how it is for line graphs, so I
> switched to XY Scatter plot as was suggested. Unfortuneately, the same
> thing
> happens. It's just that instead of dates on the x-axis it shows just
> incrementing numbers (1, 2, 3, etc....).
>
> I know the values in the array are correct, because I looked at it as the
> code was running. I think this has something to do with assigning the
> XValues property of the chart to an array, but not 100% sure.
>
> Any help possible would be appreciated.



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: creating chart Gord Dibben Microsoft Excel New Users 0 6th Sep 2009 04:25 PM
Creating a mix of column and scatter chart on one chart. Matt G Microsoft Excel Charting 1 17th Jun 2009 05:25 AM
Creating chart from vb.net Reinhard Microsoft Excel Charting 2 13th Dec 2007 01:13 PM
creating a pie chart =?Utf-8?B?Ymx1ZQ==?= Microsoft Excel Charting 1 20th Apr 2006 09:04 AM
Creating a chart via vba Snedker Microsoft Excel Charting 1 4th Dec 2003 01:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:57 AM.