You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Removing gaps for irregular time data on DateTimeAxis #83
cwevers 2013-10-18 15:44
I'm currently building a candlestick graph for stock quotes. I only have data (OHLC) for the trading days so this leaves gaps for weekend days. Of course I can work with a category axis but this throws out all the neat DateTimeAxis features. Is it possible
to remove these gaps (see attached example)? I've looked into IntervalType = DateTimeIntervalType.Manual but that seems to do nothing.
One way to deal with this problem is to use a category axis. Unfortunately it means some adjustments which are not very convenient:
1/ category axis is using the index of the label collection items as coordinates. If you have 5 categories in the Labels collection, the categories will be placed at coordinates 0 to 4
2/ CandleStickAndVolumeSeries is using a datetime converted as double (to convert, use DateTimeAxis.ToDouble(YourDateTimeValue))
So to have it working I currently use a variable storing my list of datetimes (to later pass them to the category axes), and I replace them in the CandleStickAndVolumeSeries by the index. It allows to correctly plot the data on a category axis and remove the gaps. Unfortunately it has a few downsides:
1/ the auto update of the interval doesn't exist with CategoryAxes (and it looks awful)
2/ it can delete gaps that are not real gaps. Exemple: let's imagine a H1 (1 hour interval) chart on the Forex without any quotation received on Tuesday from 3pm until 6pm, those 3 hours will not appear on your x axis, if you don't pass a "fake" candle (open = high = low = close = pastclose).
So can it be possible to have a DateTimeCategoryAxis that would plot using the label index, but will automatically update the label format (changing from hh:mm to dd/MM/yyyy regarding the zoom, like a DateTimeAxis) and its interval?
At best, the CandleStickAndVolumeSeries should have a Xprime value representing the index, with an option to choose to plot using X (the double representing the datetime, for graphs using a proper DateTimeAxis) or Xprime (the index, for graph using the new DateTimeCategoryAxis).
Hi,
i took the approach of BrianARice and modified it for my needs. I ve added a new class Financial Axis that uses indexes instead of DateTimes. With that i was able to fix eaven the tooltip dates which were otherwise broken here is my code:
public class FinancialChartAxis : LinearAxis
{
public FinancialChartAxis(List<DateTime> dateTimes, string axisDateFormatString)
: base()
{
DateTimes = dateTimes;
LabelFormatter = (value) =>
{
return value >= 0 && value < dateTimes.Count ? dateTimes[(int)value].ToString(axisDateFormatString) : string.Empty;
};
}
private List<DateTime> DateTimes { get; set; }
public override object GetValue(double x)
{
int indexValue = (int)x;
if (indexValue >= 0 && indexValue < DateTimes.Count)
{
return DateTimes[indexValue];
}
return base.GetValue(x);
}
}
Activity
MrJul commentedon Nov 11, 2014
+1, I need to show only business hours in some graph (removing week-ends and night hours).
Jofta commentedon Feb 26, 2015
Anything new here? I’ve got this code for displaying currency pair EUR/USD one hour (H1) chart:
There is for example gap between Friday 2015.02.13 23:00 and Monday 2015.02.16 00:00. My solution with OxyPlot gives me that gap on the chart:
But, I’d like to have a chart without that gap. For example this is a MT4 chart with this situation:
A lot of financial series are with gaps. I think to solve this problem would by a great improvement.
Any help will be welcome.
P.S.: OxyPlot is a good job. Thanks a lot.
PsykotropyK commentedon May 29, 2015
Hello.
One way to deal with this problem is to use a category axis. Unfortunately it means some adjustments which are not very convenient:
1/ category axis is using the index of the label collection items as coordinates. If you have 5 categories in the Labels collection, the categories will be placed at coordinates 0 to 4
2/ CandleStickAndVolumeSeries is using a datetime converted as double (to convert, use DateTimeAxis.ToDouble(YourDateTimeValue))
So to have it working I currently use a variable storing my list of datetimes (to later pass them to the category axes), and I replace them in the CandleStickAndVolumeSeries by the index. It allows to correctly plot the data on a category axis and remove the gaps. Unfortunately it has a few downsides:
1/ the auto update of the interval doesn't exist with CategoryAxes (and it looks awful)
2/ it can delete gaps that are not real gaps. Exemple: let's imagine a H1 (1 hour interval) chart on the Forex without any quotation received on Tuesday from 3pm until 6pm, those 3 hours will not appear on your x axis, if you don't pass a "fake" candle (open = high = low = close = pastclose).
So can it be possible to have a DateTimeCategoryAxis that would plot using the label index, but will automatically update the label format (changing from hh:mm to dd/MM/yyyy regarding the zoom, like a DateTimeAxis) and its interval?
At best, the CandleStickAndVolumeSeries should have a Xprime value representing the index, with an option to choose to plot using X (the double representing the datetime, for graphs using a proper DateTimeAxis) or Xprime (the index, for graph using the new DateTimeCategoryAxis).
BrianARice commentedon Nov 22, 2017
+1, this is super important for financial charts.
BrianARice commentedon Nov 22, 2017
This works pretty easily though:
andreas-it-dev commentedon Dec 27, 2017
@BrianARice should your code remove the gaps?
p80ric commentedon Aug 31, 2018
Hi,
i took the approach of BrianARice and modified it for my needs. I ve added a new class Financial Axis that uses indexes instead of DateTimes. With that i was able to fix eaven the tooltip dates which were otherwise broken here is my code:
using the code of the example:
lefig commentedon Jan 11, 2020
This is a fascinating thread and a great project. I deal with similar time series data and learnt a good deal to get started.