Profile Picture

More problems with PagingView and ScaleConfigurator on an NStockSeries

Posted By David Cobbold 12 Years Ago

More problems with PagingView and ScaleConfigurator on an NStockSeries...

Author
Message
Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi David,

It will be more complicated that that - you need to create a per day rule with associated time schudule in case your data is at 30 min interval.



Best Regards,
Nevron Support Team



David Cobbold
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 7, Visits: 1
By intraday data i mean data at a lower interval than daily. e.g. a bar for every 30 minutes of the day.

The below code is a sample of what I'm trying to do. It populates a chart using random 30 minute data but with random bars excluded so there are gaps between plenty of bars. It then uses the FocusTime() function to focus on midnight 02/02/12. As it is this works fine, but I would like the chart to not display these missing bars as gaps and instead just show whatever bars I populate the chart with continuously.

It sounds like you're saying i need to calculate the time ranges of all missing bars and add these ranges to a NDateTimeRangeRule, which to me seems to make this more complicated than it should be. Is there no other way to achieve this?

private void MainWindow_Initialized(object sender, EventArgs e)
{
NCartesianChart chart = new NCartesianChart();
chart.Axis(StandardAxis.PrimaryX).ScrollBar.Visible = true;
chart.Axis(StandardAxis.PrimaryX).ScrollBar.ResetButton.Visible = false;
chart.Axis(StandardAxis.PrimaryY).ScrollBar.Visible = true;
chart.Axis(StandardAxis.PrimaryY).ScrollBar.ResetButton.Visible = false;
_chartContainer.Controller.Tools.Add(new NTooltipTool());
_chartContainer.Controller.Tools.Add(new NAxisScrollTool());
_chartContainer.Charts.Clear();
_chartContainer.Charts.Add(chart);
_chartContainer.Legends.Clear();

NStockSeries stockSeries = (NStockSeries)chart.Series.Add(SeriesType.Stock);
stockSeries.CandleStyle = CandleStyle.Bar;
stockSeries.CandleWidth = new NLength(0.2f, NRelativeUnit.ParentPercentage);
stockSeries.CandleDepthPercent = 70;
stockSeries.UpFillStyle = new NColorFillStyle(System.Drawing.Color.White);
stockSeries.UpStrokeStyle.Color = System.Drawing.Color.Black;
stockSeries.DownFillStyle = new NColorFillStyle(System.Drawing.Color.Red);
stockSeries.DownStrokeStyle.Color = System.Drawing.Color.Black;
stockSeries.HighLowStrokeStyle.Color = System.Drawing.Color.Black;
stockSeries.DataLabelStyle.Visible = false;
stockSeries.UseXValues = true;
stockSeries.InflateMargins = true;

Random random = new Random();
double open = 100.0;
DateTime currTime = new DateTime(2012, 01, 01, 00, 00, 00);
for (int i = 0; i < 2000; ++i)
{
if (random.Next(3) != 0)
{
double high = open + random.NextDouble();
double low = open - random.NextDouble();
double close = low + (random.NextDouble() * (high - low));
stockSeries.AddDataPoint(new NStockDataPoint(open, high, low, close, currTime));
string tooltip = string.Format("{0}", currTime);
stockSeries.InteractivityStyles.Add(stockSeries.XValues.Count - 1, new NInteractivityStyle(true, null, tooltip));
open = close;
}
currTime = currTime.AddMinutes(30.0);
}

NValueTimelineScaleConfigurator scaleX = new NValueTimelineScaleConfigurator();
NWeekDayRule wdr = new NWeekDayRule(WeekDayBit.All);
scaleX.Calendar.Rules.Add(wdr);
scaleX.EnableCalendar = true;

chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = scaleX;

FocusTime(stockSeries, chart, new DateTime(2012, 02, 02));

_chartContainer.Refresh();
}

private void FocusTime(NStockSeries stockSeries, NCartesianChart cartChart, DateTime dateTime)
{
int index = 0;
bool found = false;
while (!found && index < stockSeries.XValues.Count - 1)
{
DateTime date = DateTime.FromOADate((double)stockSeries.XValues.GetValueForIndex(index + 1));
if (date > dateTime)
{
found = true;
break;
}
++index;
}

if (found)
{
DateTime startDate = DateTime.FromOADate((double)stockSeries.XValues.GetValueForIndex(index));
DateTime endDate = DateTime.FromOADate((double)stockSeries.XValues[Math.Min(index + 120, stockSeries.XValues.Count - 1)]);
NNumericAxisPagingView dateAxis = new NNumericAxisPagingView(new NRange1DD(startDate.ToOADate(), endDate.ToOADate()));
dateAxis.Enabled = true;
cartChart.Axis(StandardAxis.PrimaryX).PagingView = dateAxis;
_chartContainer.Refresh();
}
}

Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi David,

You need to exclude days on a day by day basis as shown in the code example above - for example:

 NDateTimeRangeRule rule = new NDateTimeRangeRule(new NDateTimeRange(dt, dt + new TimeSpan(1, 0, 0, 0)), false);
NDateTimeScaleConfigurator dtScale = result.Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NDateTimeScaleConfigurator;
dtScale.Calendar.Rules.Add(rule);

removes the day pointed by "dt" from the scale.

what do you mean by intraday data - please elaborate.

Also please note that you need to use a recent version of the control - there were problems with the date time scale combined with calendar in previous releases. Can you post the code you use to populate the chart and then scroll to the specified range for review?



Best Regards,
Nevron Support Team



David Cobbold
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 7, Visits: 1

My last post was a little rambling, so i'll try to be clearer. Currently if I have an NStockSeries and if I populate it with a bar for Monday, Wednesday, and Friday it will show these bars with gaps inbetween where Tuesday and Thursday should be. I would like it to just display Mon, Wed, and Fri with no gaps (i.e. whatever bars I give it).

I was previously accomplishing this using the NWeekDayRule but I have intraday data so I can't block out full days.

Also if I do use the NWeekDayRule and scroll to a specific date using the PagingView algorithm in the last post, it doesn't scroll to the correct date. However when I remove the NWeekDay rule it does scroll to the correct place, but I am left with the gaps on my chart that I don't want.

Hope this helps

David



Nevron Support
Posted 12 Years Ago
View Quick Profile
Supreme Being

Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)Supreme Being (4,435 reputation)

Group: Forum Members
Last Active: Last Week
Posts: 3,054, Visits: 4,009

Hi David,
There were some issues in the date time calendar which were fixed in recent editions of the control - what is the version you're currently testing with?
Regarding how to exclude days on a per day basis - for this purpose you need to use the NDateTimeRangeRule - the following example shows how to do that dynamically when you click on a bar:

  private void Form1_Load(object sender, EventArgs e)
  {
   NCartesianChart chart = (NCartesianChart)nChartControl1.Charts[0];
   chart.BoundsMode = BoundsMode.Stretch;

   NBarSeries bar = new NBarSeries();
   bar.UseXValues = true;

   Random rand = new Random();
   DateTime now = DateTime.Now;
   for (int i = 0; i < 10; i++)
   {
    bar.Values.Add(rand.Next(100));
    bar.XValues.Add(now);
    now += new TimeSpan(1, 0, 0, 0);
   }

   chart.Series.Add(bar);
   nChartControl1.MouseDown += new MouseEventHandler(nChartControl1_MouseDown);

   NDateTimeScaleConfigurator dtScale = new NDateTimeScaleConfigurator();
   dtScale.MajorTickMode = MajorTickMode.CustomStep;
   dtScale.CustomStep = new Nevron.NDateTimeSpan(1, NDateTimeUnit.Day);
   chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator = dtScale;
   dtScale.EnableCalendar = true;
  }

  void nChartControl1_MouseDown(object sender, MouseEventArgs e)
  {
   NHitTestResult result = nChartControl1.HitTest(e.X, e.Y);

   if (result.ChartElement == ChartElement.DataPoint)
   {
    NBarSeries bar = (NBarSeries)result.Series;

    DateTime dt = DateTime.FromOADate((double)bar.XValues[result.DataPointIndex]);

    NDateTimeRangeRule rule = new NDateTimeRangeRule(new NDateTimeRange(dt, dt + new TimeSpan(1, 0, 0, 0)), false);
    bar.RemoveDataPointAt(result.DataPointIndex);

    NDateTimeScaleConfigurator dtScale = result.Chart.Axis(StandardAxis.PrimaryX).ScaleConfigurator as NDateTimeScaleConfigurator;
    dtScale.Calendar.Rules.Add(rule);

    nChartControl1.Refresh();
   }
  }

Hope this helps - let us know if you meet any problems...

 



Best Regards,
Nevron Support Team



David Cobbold
Posted 12 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: Forum Members
Last Active: 12 Years Ago
Posts: 7, Visits: 1
I posted similar problems a while ago, but on new data i'm having more problems.

My first problem is that I have data that may be on any day of the week, but I want the stock series to display them with no gaps. Previously I was using NValueTimelineScaleConfigurator with a NWeekDayRule to not show Saturday or sunday, but now what i'm looking for is to just display whatever bars I give the chart with no gaps in between due to missing values on certain days. Is this possible?

My second problem is that i would like to programatically scroll to a specified date, which i'm doing using the NNumericAxisPagingView (as in my other thread). But when combined with the NWeekDayRule and data that doesn't every day, this isn't scrolling to the correct place in the chart. My code is similar to before, although now will display 120 bars worth of data:


DateTime startDate = DateTime.FromOADate((double)stockSeries.XValues.GetValueForIndex(index));
DateTime endDate = DateTime.FromOADate((double)stockSeries.XValues[Math.Min(index + 120, stockSeries.XValues.Count - 1)]);
NNumericAxisPagingView dateAxis = new NNumericAxisPagingView(new NRange1DD(startDate.ToOADate(), endDate.ToOADate()));
dateAxis.Enabled = true;
cartChart.Axis(StandardAxis.PrimaryX).PagingView = dateAxis;
_chart.Refresh();


(where index is the previously calculated index of the chosen date to scroll to)


However once I comment out the NWeekDayRule code, this scrolling logic works correctly. So Is there some solution that will solve both of these problems?

Thanks.



Similar Topics


Reading This Topic