X-Axis Intervals and X-Axis Format are not not working

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 = 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

};

}

}






12 Replies

GM Gayathri Manickam Syncfusion Team January 19, 2022 03:35 PM UTC

Hi Lorenzo,

We have analyzed your query with the provided code snippet, and we would like to let you know that you have used the double range for setting min max info instead of using DateTimeRange. Hence please set DateTimeRange for the PrimaryXAxis and provide Datetime format. Also, we have prepared sample based on the provided code snippet and your requirement. Please find the sample below.

For more details, please refer below UG link.
https://help.syncfusion.com/windowsforms/chart/chart-axes#specifying-custom-ranges

Sample: https://www.syncfusion.com/downloads/support/forum/172093/ze/CandleSeriesChart762542425.zip

Please let us know if you have any other queries. 

Regards, 
Gayathri M 



LO Lorenzo January 19, 2022 09:54 PM UTC

Hi Gayathri,


I noticed a few buggy issues so I will respond as soon as I have run some tests and different scenarios



LO Lorenzo January 20, 2022 11:56 AM UTC

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?




YP Yuvaraj Palanisamy Syncfusion Team January 20, 2022 04:57 PM UTC

Hi Lorenzo, 
 
Currently we are validating the reported queries and we will update you with complete detail on or before 24th January 2022. We appreciate your patience until then. 
 
Regards, 
Yuvaraj. 



GM Gayathri Manickam Syncfusion Team January 24, 2022 01:48 PM UTC

Hi Lorenzo, 
 
We were unable to validate the reported issues due to images are not shown in your previous update. We request you to again share the images in zip file format to proceed further.  
 
Regards,  
Gayathri M 



LO Lorenzo replied to Lorenzo January 24, 2022 02:17 PM UTC

Oh man, ok thanks Gayathri. I will add images in the way you suggested and re-post soon. 



LO Lorenzo January 24, 2022 03:26 PM UTC

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)


Attachment: Forum_Pics_caef4249.zip


GM Gayathri Manickam Syncfusion Team January 25, 2022 05:52 PM UTC

Hi Lorenzo, 
 
Issue 2: Setting bars to hours seems to add X intervals to each bar rather than 1 interval every X bars.
Issue 3: It seems the start end dates are not working. (Or maybe I don't correctly understand how this property works

You can resolve the above two reported issues by setting Indexed property of the chartControl to false as shown in below code snippet. 
 
this.chartControl1.Indexed = false; 
 
Issue 4: The rendered chart seems to break if I set the DateTimeRange AFTER the model has been implemented.

You need to set the DateTimeRange for the chart before adding the series to the chart and it is not based on the model implemented. 
 
Regards,  
Gayathri M 



LO Lorenzo January 25, 2022 06:54 PM UTC

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?



DD Devakumar Dhanapoosanam Syncfusion Team January 26, 2022 02:00 PM UTC

Hi Lorenzo, 
 
Query: Then there will be gaps in the bar data for dates like weekends, when there is no data. How can one avoid that? 
 
Currently we are analyzing the reported query at our end, and we will update you with complete details on January 27, 2022.  
 
Regards, 
Devakumar D 



ME Manivannan Elangovan Syncfusion Team January 27, 2022 04:22 PM UTC

Hi Lorenzo, 

We are still validating the reported query at our end, and we will update you with complete details by tomorrow January 28th, 2022.  

Regards, 
Manivannan E 


ME Manivannan Elangovan Syncfusion Team January 28, 2022 05:39 PM UTC

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


Loader.
Up arrow icon