Dynamic data display

I am trying to display candlesticks for a stock price chart. I have a marker for every minute of the trading day - from 9:30 to 16:00. I do not want to display empty space for 4:01 pm to 9:29 am for each trading day. Is there any way to remove this time span from the x axis on my chart? I want all the data to look continuous without interruption in the stream. I am using NumericAxis for the X axis with the type TickToDateTimeLabelProvider I created. Is there a way to change LabelProvider to suit my needs? Or does it stretch deeper?

Here is my code for LabelProvider:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; namespace Microsoft.Research.DynamicDataDisplay.Charts { public class TickToDateTimeLabelProvider : NumericLabelProviderBase { public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var res = new TextBlock[ticksInfo.Ticks.Length]; for (int i = 0; i < ticksInfo.Ticks.Length; ++i) { long l = (long)ticksInfo.Ticks[i]; if (l < 0) l = 0; DateTime dt = new DateTime(l); res[i] = new TextBlock(); res[i].Text = dt.ToString(); } return res; } } } 
+4
source share
1 answer

Having solved this, I ended up doing X, displaying the position at which the data was in the collection, and then making the new label provider for changing the positions in DateTimes that I wanted. My new shortcut provider is as follows:

 using System; using System.ComponentModel; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using Microsoft.Research.DynamicDataDisplay.Charts.Axes; using System.Globalization; namespace Microsoft.Research.DynamicDataDisplay.Charts { public class TradingLabelProvider : NumericLabelProviderBase { private List<DateTime> m_Labels; public List<DateTime> Labels { get { return m_Labels; } set { m_Labels = value; } } public TradingLabelProvider(DateTime start, List<DateTime> labels) { Labels = labels; } public override UIElement[] CreateLabels(ITicksInfo<double> ticksInfo) { var ticks = ticksInfo.Ticks; Init(ticks); UIElement[] res = new UIElement[ticks.Length]; LabelTickInfo<double> tickInfo = new LabelTickInfo<double> { Info = ticksInfo.Info }; for (int i = 0; i < res.Length; i++) { tickInfo.Tick = ticks[i]; tickInfo.Index = i; string labelText = ""; if(Convert.ToInt32(tickInfo.Tick) <= Labels.Count && tickInfo.Tick >= 0) { labelText = Labels[Convert.ToInt32(tickInfo.Tick)].ToString(); } TextBlock label = (TextBlock)GetResourceFromPool(); if (label == null) { label = new TextBlock(); } label.Text = labelText; label.ToolTip = ticks[i].ToString(); res[i] = label; ApplyCustomView(tickInfo, label); } return res; } } } 

This allowed me to bring days together without a gap between them to meet my requirements. I struggled to do this using DateTimeAxis, but to no avail.

+2
source

Source: https://habr.com/ru/post/1440321/


All Articles