Jump to content
Software FX Community

Scrolling at DateTime X-Axis


User (Legacy)

Recommended Posts

Hello,

the X-axis of my chart is of type DateTime (including the time part).

I'd like to have a scrollbar for this Axis, so I set

onlineChart.AxisX.AutoScroll = true;

The question is: How great must PixelsPerUnit be?

In the explanation for this property the calculation is done using the width

of the chart (my chart is 570 pixels wide), the number of pages ('2' for

example) and the Maximum. But what is the Maximum of a DateTime X-axis?

The X-value of the first point of the first series is

Double firstX = onlineChart.Data.X[0,0] = 38911,5832638889

which accords to 13.07.2006 13:59:54.

The X-value of the last point is of the first series is

Double lastX = onlineChart.Data.X[0, onlineChart.Data.Points - 1] =

38911,6042708333

which accords to 13.07.2006 14:30:09

I tried to calculate PixelsPerUnit as

PPU = 570 / lastX / 2 and as

PPU = 570 / (lastX - firstX) / 2

but I never get a scrollbar....

Kind regards,

MusiMeli

Link to comment
Share on other sites

What type of chart is this ?

I ask this question because there is basically two ways in which Chart FX

uses X-Values (dates in this case)

1) An X/Y chart: Each point is positioned in the X-Axis according to its

X-Value.

2) Data-Driven X-Axis: Data points are positioned sequentially in X and the

X-Value is use to label the X-Axis only. The X-Axis remains a categorical

axis.

The desicion on which method is used (1 or 2) is made based on the Gallery

being used, Line, Area, Scatter, Curve, Curve-Area, Step and Bubble all

support X-Axis positioning and therefore are drawn using the first method

(1), Bar, Cube, Financial, Gantt do NOT support X-Axis positioning and

therefore are drawn using the second method (2).

When the X-Axis is Data-Driven, the label values are actually indexes in the

data not actual X-Values, therefore, each unit refers to one POINT,

regardless of how often points are plotted, setting PixelsPerUnit = 30, will

allot 30 pixels for each point in the chart.

If, in the other hand, the X-Axis is a true numeric axis, each unit

corresponds to one unit in the scale of the X-Values, in the case of dates,

that would be one DAY.

I hope this information gets you in the right direction.

--

Francisco Padron

www.chartfx.com

Link to comment
Share on other sites

Hi Francisco,

> What type of chart is this ?

It´s a line chart (X/Y) with a true numeric axis.

> If, in the other hand, the X-Axis is a true numeric axis, each unit

> corresponds to one unit in the scale of the X-Values, in the case of

> dates, that would be one DAY.

> I hope this information gets you in the right direction.

Yes, the formula is:

Chart.AxisX.PixelsPerUnit = width of chart * 1440 / number of minutes to

show at once

(because 1 day = 24*60 min = 1440 min)

Thanks, MusiMeli

Link to comment
Share on other sites

The following code, applied to a default line chart works for me:

int const MAXPOINTS = 100;

chart1.AxisX.LabelsFormat.Format = AxisFormat.Time;

DateTime start = new DateTime(2005,6,18);

DateTime date = start;

Random rand = new Random();

chart1.Data.Series = 1;

chart1.Data.Points = MANYPOINTS;

for (int i = 0; i < MANYPOINTS; i++) {

chart1.Data.Y[0,i] = rand.Next(100);

chart1.Data.X[0,i] = date.ToOADate();

date = date.AddMinutes(10);

}

chart1.AxisX.AutoScroll = true;

chart1.AxisX.SetScrollView(start.ToOADate(),start.AddMinutes(60).ToOADate());

//chart1.AxisX.PixelsPerUnit = (chart1.Width * 1440.0) / 30.0; This is not

accurrate becase chart1.Width includes borders, legend box, etc,

SetScrollView is recomended.

--

Francisco Padron

www.chartfx.com

Link to comment
Share on other sites

Hello Francisco,

your code works nearly fine. But I think, with

chart1.AxisX.SetScrollView(start.ToOADate(),start.AddMinutes(60).ToOADate());

the first visible datapoint should be at 00:00:00 and the last one at

01:00:00.

Running your code, the last visible datapoint is at 00:50:00.

And if I change the Format to AxisFormat.DateTime,

the last visible point is at 2005-06-18 00:40:00

=> even one point less!

Why?

--

MusiMeli

> The following code, applied to a default line chart works for me:

>

> int const MAXPOINTS = 100; ////////// const int MANYPOINTS = 100;

> !!!

> chart1.AxisX.LabelsFormat.Format = AxisFormat.Time;

>

> DateTime start = new DateTime(2005,6,18);

>

> DateTime date = start;

>

> Random rand = new Random();

>

> chart1.Data.Series = 1;

>

> chart1.Data.Points = MANYPOINTS;

>

> for (int i = 0; i < MANYPOINTS; i++) {

>

> chart1.Data.Y[0,i] = rand.Next(100);

>

> chart1.Data.X[0,i] = date.ToOADate();

>

> date = date.AddMinutes(10);

>

> }

>

> chart1.AxisX.AutoScroll = true;

>

> chart1.AxisX.SetScrollView(start.ToOADate(),start.AddMinutes(60).ToOADate());

>

> //chart1.AxisX.PixelsPerUnit = (chart1.Width * 1440.0) / 30.0; This is not

> accurrate becase chart1.Width includes borders, legend box, etc,

> SetScrollView is recomended.

>

>

> --

> Francisco Padron

> www.chartfx.com

>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...