Drawing a chart

P

Preben Zacho

Hi there

I'm new to charts and I'm trying to create a chart that shows development of
a share/portfolio over a 6 month period. The chart should show the closing
rate for the share for each day (make it about 180 days). However, on the
X-axis I only want to show 6 ticks, one for each of the months. I can't make
that work.

In the following excaple (from C#) I try to display values for an entire
year but only display 4 months on the X-axis. So you should still be able to
see that values for fx. Feb, Mar in between Jan and April. Hope this makes
sense to you. Here is the sample code:

using AxMicrosoft.Office.Interop.Owc11;
using Microsoft.Office.Interop.Owc11;

private AxMicrosoft.Office.Interop.Owc11.AxChartSpace axChartSpace1;
string XCategories = "Jan,Apr,Jul,Oct";
string XValues = "12,13,14,12,14,15,16,17,19,20,31,21";

// First add a chart to the chart space
Microsoft.Office.Interop.Owc11.ChChart chart = axChartSpace1.Charts.Add(0);


// Now add a new serie to the collection
chart.SeriesCollection.Add(0);

// Add the categories
chart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimCategories,
(int)ChartSpecialDataSourcesEnum.chDataLiteral, XCategories);
// Add the values
chart.SeriesCollection[0].SetData (ChartDimensionsEnum.chDimValues,
(int)ChartSpecialDataSourcesEnum.chDataLiteral, XValues);
//Set tick spacing = 4 (in other words, only show the 4 months as the Axis
names, but display all 12 values for the entire year. This does not work
properly).
chart.Axes[0].TickLabelSpacing = 4;

The result is a chart where only the first 4 values are shown and ONLY "Jan"
is displayed on the axis.

Regards

Preben Zacho
 
P

Preben Zacho

Ok, got it working now:: Take the total number of values in the collection
and divide it with the spacing number between the ticks. The category names
should then be placed at a position with this number as interval.

Fx. if you have 48 values and want 6 spaces between each ticks, divide 48
with 6 = 8. So the category name should be placed in every 8th position in
the XCategories variable. Sounds simple enough.

/PZ
 

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