Hi,
I am building a chart with stock trading data.
I have an indexed chart (so that there are no gaps for weekends...etc).
And I have set the PrimaryXAxis.DateTimeFormat to "MMM dd HH:mm"
I then zoom the chart on rendering. And attempt to set the x interval by setting MinMaxInfo on PrimaryXAxis.Range.
When the chart renders, the intervals don't seem to change at all, and the DateTime Format is different.
My implementation is below (where Bar is a poco object with HLOC values and a datetime Timestamp for the X value).
Does anyone know how to get the intervals to work properly? As well as the DateTimeFormat?
//class variable
private ChartSeries _series;
//in the constructor
_series = new("Prices", ChartSeriesType.Candle);
chart.Series.Add(_series);
//code to load the Bar objects into the model/chart
public void LoadBars(List
{
// bars = bars.GetRange(0, 100); //100 bars for testing
BarModel model = new(bars.ToArray());
//_series.SeriesIndexedModelImpl = model;
_series.SeriesModel = model;
chart.PrimaryXAxis.ValueType = ChartValueType.DateTime;
chart.PrimaryXAxis.DateTimeFormat = "MMM dd HH:mm";
//index it to avoid gaps
chart.Indexed = true;
//I want to see about 50 bars on the chart
int barsToSee = 50;
double pctBars = 1.0 * barsToSee / bars.Count;
chart.PrimaryXAxis.ZoomFactor = pctBars;
chart.PrimaryXAxis.ZoomPosition = 1 - pctBars;
//set the interval
chart.PrimaryXAxis.RangeType = ChartAxisRangeType.Set;
chart.PrimaryXAxis.Range = new MinMaxInfo(0, bars.Count - 1, 12);
}
// IChartSeriesModel Implementation
public class BarModel : IChartSeriesModel
{
private readonly Bar[] _data;
public BarModel(Bar[] data)
{
_data = data;
}
// Returns the number of points in this series.
public int Count => _data.GetLength(0);
// Event that should be raised by any implementation of this interface if data that it holds changes. This will cause the chart to be updated accordingly.
public event ListChangedEventHandler? Changed;
// Indicates whether a specified point index has a value which can be plotted.
public bool GetEmpty(int xIndex)
{
return false;
}
public double GetX(int xIndex)
{
return _data[xIndex].TimestampDt.ToOADate();
}
// Returns the Y value of the series at the specified point index.
public double[] GetY(int xIndex)
{
return new double[]
{
_data[xIndex].BidHigh,
_data[xIndex].BidLow,
_data[xIndex].BidOpen,
_data[xIndex].BidClose
};
}
}
Hi Gayathri,
I noticed a few buggy issues so I will respond as soon as I have run some tests and different scenarios
Hi Gayathri
I listed below 4 issues I encountered when trying to implement the provided snippet. The first I was able to partially resolve. But for the 3 others I require some guidance.
Issue 1 (RESOLVED) - X-Axis Grid lines seem to be static and dictate the time interval.
Despite the fact that the bar times were 00:00 when they were loaded into the BarModel, when the format is set to ‘MMM dd HH:mm’ the minutes are not 00:00 despite the snippet creating daily bars.
When I tried scrolling the x-axis I noticed that the grid lines seem static while the bars move, and at the same time, the time on the intervals change,
RESOLUTION - I resolved this by setting
this.chartControl1.PrimaryXAxis.TickDrawingOperationMode = ChartAxisTickDrawingOperationMode.IntervalFixed;
Issue 2 (NEED HELP) - Setting bars to hours seems to add X intervals to each bar rather than 1 interval every X bars.
I decided to look at hourly bars. I commented out and replaced the snippet with the following (leaving intervals at 5).
This is the behavior I saw, where it seems almost like 5 intervals is being set to each bar, which is strange. How can I get the interval to show for every 5 bars, like it was doing for the Daily Bars?
ISSUE 3 (NEED HELP) - It seems the start end dates are not working. (Or maybe I don't correctly understand how this property works).
I put the code back to daily bars, and I configured the date range start at {date}, and end at {date.AddDays(10)}; Based on the documentation it seems that the range on the rendered chart should only include the bars with that date range. However, all the bars that were created are still shown on the chart.
All the bars are still showing, not 10 days.
I even tried using DateTime.MinValue for start and end dates, and the result was exactly the same.
Am I setting this up in correctly or is something wrong? If my understanding is incorrect, then what is the meaning of start and end date in the DateTimeRange property?
ISSUE 4 (NEED HELP) - The rendered chart seems to break if I set the DateTimeRange AFTER the model has been implemented.
1 - I commented out the DateTimeRange assignment
2 - I then moved it to the point right BEFORE the function where I implement the BarModel class
3 - The bars render
4 - I then move the assignment to DateTimeRange to the point AFTER implementing the BarModel class.
5 - And NO bars render. Despite the last bar being dated March 31, the x-axis shows April 16.
Is this an issue or is this expected? If this is expected, how would I correctly change the DateTimeRange after the bar model has been implemented?
Oh man, ok thanks Gayathri. I will add images in the way you suggested and re-post soon.
Hi Gayathri
Below is the same message that I sent above, only with screenshots replaced with references to the .png file names in the attached zip file. Please let me know if you need any more information from me.
Lorenzo
I listed below 4 issues I encountered when trying to implement the provided snippet. The first I was able to partially resolve. But for the 3 others I require some guidance.
Issue 1 (RESOLVED) - X-Axis Grid lines seem to be static and dictate the time interval.
Despite the fact that the bar times were 00:00 when they were loaded into the BarModel, when the format is set to ‘MMM dd HH:mm’ the minutes are not 00:00 despite the snippet creating daily bars.
(PIC1)
When I tried scrolling the x-axis I noticed that the grid lines seem static while the bars move, and at the same time, the time on the intervals change,
(PIC2)
RESOLUTION - I resolved this by setting
this.chartControl1.PrimaryXAxis.TickDrawingOperationMode = ChartAxisTickDrawingOperationMode.IntervalFixed;
Issue 2 (NEED HELP) - Setting bars to hours seems to add X intervals to each bar rather than 1 interval every X bars.
I decided to look at hourly bars. I commented out and replaced the snippet with the following (leaving intervals at 5).
(PIC3)
This is the behavior I saw, where it seems almost like 5 intervals is being set to each bar, which is strange. How can I get the interval to show for every 5 bars, like it was doing for the Daily Bars?
(PIC4)
ISSUE 3 (NEED HELP) - It seems the start end dates are not working. (Or maybe I don't correctly understand how this property works).
I put the code back to daily bars, and I configured the date range start at {date}, and end at {date.AddDays(10)}; Based on the documentation it seems that the range on the rendered chart should only include the bars with that date range. However, all the bars that were created are still shown on the chart.
(PIC5)
All the bars are still showing, not 10 days.
I even tried using DateTime.MinValue for start and end dates, and the result was exactly the same.
Am I setting this up in correctly or is something wrong? If my understanding is incorrect, then what is the meaning of start and end date in the DateTimeRange property?
(PIC6)
ISSUE 4 (NEED HELP) - The rendered chart seems to break if I set the DateTimeRange AFTER the model has been implemented.
1 - I commented out the DateTimeRange assignment
(PIC7)
2 - I then moved it to the point right BEFORE the function where I implement the BarModel class
(PIC8)
3 - The bars render
(PIC9)
4 - I then move the assignment to DateTimeRange to the point AFTER implementing the BarModel class.
(PIC10)
5 - And NO bars render. Despite the last bar being dated March 31, the x-axis shows April 16.
Is this an issue or is this expected? If this is expected, how would I correctly change the DateTimeRange after the bar model has been implemented?
(PIC11)
|
this.chartControl1.Indexed = false; |
If I set this.chartControl1.Indexed = false;
Then there will be gaps in the bar data for dates like weekends, when there is no data. How can one avoid that?
Hi Lorenzo,
We have checked the reported issue and would like to inform you that when we set the Indexed property to true, the series is plotted for all x-values and range is not considered. This is not an issue, current behavior of ChartControl. The DateTimeRange is only considered if the indexed value is set to false and the ValueType of the axis is set to DateTime.
Currently we don’t have direct support to avoid weekdays and holidays in DateTime type axis. For this requirement, we have already logged a feature request on this, and it can be tracked through our feedback portal below.
Link: https://www.syncfusion.com/feedback/1338/support-for-business-hours-in-datetime-axis
Please cast your vote to make it count. We will prioritize the features every release based on the demands.
If you have any more specification/suggestions to the feature request, you can add it as a comment in the portal.
Thanks,
Manivannan E