|
Finance Chart X-axis labels |
Posted by Mahima on Mar-31-2016 13:30 |
|
Hi,
I am trying to plot an intraday finance chart for an interval of 1 min. I have data starting from the first tick as shown in the attachment. Still, I am getting unusual tick differences and only hourly ticks. I want ticks with intervals in minutes say 5 min or 10 min. Please let me know if I can do it for the same.
|
Re: Finance Chart X-axis labels |
Posted by Peter Kwan on Apr-01-2016 02:41 |
|
Hi Mahima,
The built-in labelling method of the FinanceChart object assumes the chart is at least for a few hours, and the closest label spacing is one label every hour.
For intraday charts, even if there is only a few candlesticks (may be the start has just started), we suggest the timestamps array to contain the timestamps for the entire day (or at least for a few hours). The high/low/open/close and vol arrays can contain only a few values for the available data. In this way, the x-axis of the chart will cover the entire trading day, and the few candlesticks will start from the left side of the chart. The hourly labels will look natural.
If there are only a few timestamps, the x-axis of the chart will only cover one or a few minutes, and the candlesticks will become very wide. It would look unnatural.
In the "Interactive Financial Chart" sample code, for the intraday chart, there are code to extend the timestamps array if necessary to cover an entire trading day.
If you prefer to use x-axis or short intervals (less than a few hours), you may add an additional line after adding the main price chart. The code is like (in C#/Java):
//add the main price chart
XYChart mainChart = c.addMainChart(........);
//add one label every 10 minutes
m.xAxis().setMultiFormat2(Chart.StartOfMinuteFilter(10), "{value|nn}");
I note that your code seem to be using the track cursor. Instead of formatting the timestamp in the track cursor as "mmm dd, yyyy", you may consider to use "hh:nn" or "mmm dd, yyyy hh:nn". In this way, even there is only one label per hour, the user can still easily see which minute the candlestick belongs to.
Regards
Peter Kwan |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-01-2016 17:36 |
|
Hi Peter,
Thanks for the response. I appreciate your support.
In the case of a Finance chart, I am not able to access the x-axis. Is there a way to typecast Finance chart that is derived from the Multichart class to an XYChart which gives the utility to access the X and Y axis? |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-01-2016 17:44 |
|
Please ignore the above reply, got it!
Thanks |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-01-2016 19:27 |
|
Hi Peter,
Tried plotting the chart with 10min labels. But it shows inconsistent labels.
Used the following code:
((XYChart *)m.getChart(0))->xAxis()->setMultiFormat(Chart::StartOfMinuteFilter(10,0.5), "{value|h:nna}");
Attached the snapshot for reference.
|
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-01-2016 19:37 |
|
I figured out the chart depends on the window size. if I increase the size, I get the labels fine. Do you think this is the desired behavior?
If in case I have a smaller area to plot, what should I do? |
Re: Finance Chart X-axis labels |
Posted by Peter Kwan on Apr-01-2016 23:31 |
|
Hi Mahima,
If there are too many labels, and the labels tend to overlap, ChartDirector may remove some labels.
To solve the problem, please make sure your chart is large enough so that the labels do not overlap, or you may use less labels (eg. 1 label per 30 minutes for smaller charts) so that the labels do not overlap, or you may use shorter labels (such as only displaying the minutes part (use {value|nn}), as the hour part and am/pm part should be obvious to users.
For your case, since your code specifies the chart size, and your code know the number of candlesticks, it can determine how many pixels are between two labels. May be you can set a size limit for 1 label per 10 minutes, and another limit for 1 label per 20 minutes and another for 1 label per 30 minutes. If your chart is small enough that even 1 label per 30 minutes are too much, you can remove the setMultiFormat line and let ChartDirector automatically determine the labels.
Hope this can help.
Regards
Peter Kwan |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-04-2016 20:16 |
|
Hi Peter,
Thanks for the help.I plot the data without extra points too.
Also, one more thing. Is it possible for me to fetch OHLC values on hover and place buy/sell orders accordingly on clicking that point? |
Re: Finance Chart X-axis labels |
Posted by Peter Kwan on Apr-05-2016 04:14 |
|
Hi Mahima,
Yes. In the "Finance Chart Track Line" sample code, it demonstrates how to obtain the OHLC and other values when the mouse moves over the chart. The sample code uses those values to create a dynamic legend, but you can use those values for other purpose as well, such as for trading.
Hope this can help.
Regards
Peter Kwan |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-05-2016 16:08 |
|
Hi,
Thanks for the reference.
I tried connecting the clicked signal to my own slot. However the viewer returns Basechart pointer. I typecasted it to a finance chart pointer but of no use. The code crashes when trying to get the plot area. |
Re: Finance Chart X-axis labels |
Posted by Peter Kwan on Apr-06-2016 01:19 |
|
Hi Mahima,
The "Finance Chart Track Line" sample code demonstrates how to obtain the various XYChart objects inside a FinanceChart and their associated PlotArea objects. (A FinanceChart can have many XYChart objects for the main price chart and various indicators, and each XYChart can have its own PlotArea object.) In brief, the code is like:
//Get the MultiChart object (FinanceChart is a subclass of MultiChart). This assumes
//you have put a FinanceChart in the m_ChartViewer using m_ChartViewer.setChart.
MultiChart m = (MultiChart *)m_ChartViewer->getChart();
//Get the first XYChart in the FinanceChart
XYChart *c = (XYChart *)m->getChart(0);
//Get the plot area object for the XYChart
PlotArea *p = c->getPlotArea();
.....
Hope this can help.
Regards
Peter Kwan |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-06-2016 20:55 |
|
Hi Peter,
Thanks for the sugesstion. Yes it worked! |
Re: Finance Chart X-axis labels |
Posted by Mahima on Apr-07-2016 16:33 |
|
Hi Peter,
Taking reference from a previous post where OnMouseMovePlotArea event caused a crash, I created the Finance Chart Object onto a heap.
However when my ChartViewer accesses the PlotAreaMouseX it crashes on this line :
_chartViewer->getPlotAreaMouseX();
I have also created the viewer on heap in the constructor and assigned a widget to it.
_chartViewer = new QChartViewer(ui->widget); |
Re: Finance Chart X-axis labels |
Posted by Peter Kwan on Apr-08-2016 02:26 |
|
Hi Mahima,
If the code works when the FinanceChart is not created in the heap, but it crashes when the FinanceChart is created in the heap, it is likely there is some memory related issues in the code. For example, since your code created the FinanceChart on the heap, you may have code that frees the memory later. May be the memory has already been freed when the QChartViewer is trying to access the chart. Alternatively, may be there is some error in using the pointers and it overwrites the memory of other objects.
Note that in all ChartDirector sample code, the chart is already created in the heap. So whether the chart is in the heap or not should not be the issue.
As it is hard to debug the code without running the code, may be you can consider to create an example that can reproduce the problem. May be you can try to modify one of the ChartDirector sample code to try to reproduce the problem, and then attached the modified code so I can trouble-shoot the code.
Regards
Peter Kwan |
|