Simple X/Y Chart.

K

Kevin Burton

This is an extremly basic question but I have spent too much time trying to
figure it out.

I would like to chart a simple X/Y graph. However when I select a chart type
of XlChartType.xlLine it uses the first column in the array as a Y value
array. I would like to have the first column in the array to be the X values
and each subsequent column in the range to be Y1, Y2, etc. If I specify the
first column to be a date then it does just what I want. But if I specify the
first column to be say an integer or double then Excel seems to think that
this is one of the Y values. I just want a plot with the X values taken from
the first column and the Y values taken from the subsequent columns, with a
legend for each of the Y column values and the Y values connected with a
line. Like I said just like it does when the first column is a date.

Thank you.

Kevin
 
J

Jon Peltier

xlLine is not an XY chart, it is a line chart. Except for when the X values
are dates, the X values are treated as nonnumeric text labels.

Look for something like xlXYScatter or xlXYScatterLine.

- Jon
 
K

Kevin Burton

Will this type automatically create legends based on the column header
values? I found a work-around by making the X values "text" and formatting on
my own. This seems to work.

Thank you.

Kevin
 
J

Jon Peltier

In general, the SetSourceData method defines category values and series
names (legend entries) for a properly defined rata range. Otherwise you can
use the .Name, .XValues, and .Values property of each series.

What's "properly defined"? In a line or column chart, if the first column is
text or dates, it will be assigned to category labels. To make it easier for
Excel to figure out what you want, put a column header label above every
column of Y values, and keep the cell above the column of X values blank.

- 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