Display a TPointSeries when X axis is showing Date values
Posted: Wed Jan 19, 2005 6:21 pm
I am having some trouble getting a TPointSeries to display properly when the other line series on a chart are showing Date values on the XAxis.
I am using the code below to add the line series values:
// populate the chart here too
int date = ds->getDate(i);
int year = date / 10000;
int month = (date - (year * 10000)) / 100;
int day = date - (year * 10000) - (month *100);
// set the date as the label separately so we will not display weekends (i.e. gaps)
int pos = lineSeries->AddXY(i, closes->getValue(i));
AnsiString dateLabel = DateToStr(EncodeDate((Word)year, (Word)month, (Word)day));
lineSeries->Labels->Labels[pos] = dateLabel;
This code is designed to stop weekends from disrupting my data - so the chart looks as if there are five days in a week, with no 'gaps' for weekends.
I then am trying to add corresponding points into a PointSeries using the combinations below:
int pos = pointSeries->AddXY(x, y); // where x counts up from zero
pointSeries->Labels->Labels[pos] = dateLabel;
dateLabel holds the results of DateToStr(EncodeDate(year,month,day) as done for the original line series.
This causes my new points to be added at the start of my series. I also tried replacing the first parameter to AddXY with the return from EncodeDate but that also does not work. I think I need to be able to work out for a given date, which point that corresponds to in the lineSeries ?
Or is there an easier way of doing this. I have the code working fine when I am displaying times on the XAxis, because there is no need to worry about weekends then and the lineSeries->AddXY() takes the encoded time as the first parameter and I can do the same for the AddXY() call for the point series in this case.
Thanks
Stew
I am using the code below to add the line series values:
// populate the chart here too
int date = ds->getDate(i);
int year = date / 10000;
int month = (date - (year * 10000)) / 100;
int day = date - (year * 10000) - (month *100);
// set the date as the label separately so we will not display weekends (i.e. gaps)
int pos = lineSeries->AddXY(i, closes->getValue(i));
AnsiString dateLabel = DateToStr(EncodeDate((Word)year, (Word)month, (Word)day));
lineSeries->Labels->Labels[pos] = dateLabel;
This code is designed to stop weekends from disrupting my data - so the chart looks as if there are five days in a week, with no 'gaps' for weekends.
I then am trying to add corresponding points into a PointSeries using the combinations below:
int pos = pointSeries->AddXY(x, y); // where x counts up from zero
pointSeries->Labels->Labels[pos] = dateLabel;
dateLabel holds the results of DateToStr(EncodeDate(year,month,day) as done for the original line series.
This causes my new points to be added at the start of my series. I also tried replacing the first parameter to AddXY with the return from EncodeDate but that also does not work. I think I need to be able to work out for a given date, which point that corresponds to in the lineSeries ?
Or is there an easier way of doing this. I have the code working fine when I am displaying times on the XAxis, because there is no need to worry about weekends then and the lineSeries->AddXY() takes the encoded time as the first parameter and I can do the same for the AddXY() call for the point series in this case.
Thanks
Stew