ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Finance Chart how to display timeStamps
Posted by zdw on Jan-08-2019 20:19
first,I was used FinaceChart setData()Function to set timeStamps ,however,it can't be show time label.

  Re: Finance Chart how to display timeStamps
Posted by Peter Kwan on Jan-09-2019 03:42
Hi zdw,

Would you mind to clarify which programming langauge edition of ChartDirector you are using?

The timestamps need to be date/time according to the programming language (not human language). For example, in .NET, the date/time can be System.DateTime objects. In Java, it can be java.util.Date objects. Some programming languages do not have a date/time data type. In this case, the date/time needs to be constructed by using the ChartDirector chartTime or chartTime2 method. For example, in C++, it is as follows:

https://www.advsofteng.com/doc/cdcpp.htm#dateformat.htm

Note that in a financial chart, the data should be sorted based on the timestamps. If the timestamps are random or not sorted in chronological order, ChartDirector may not be able to generate suitable labels.

Another thing is that the data length must be longer than the "extraPoints" parameter in setData (the last parameter). If the extraPoints is set to 20, but the data only has 17 points, then nothing can be plotted.

Regards
Peter Kwan

  Re: Finance Chart how to display timeStamps
Posted by zdw on Jan-09-2019 06:26
thank you replyed Peter Kwan
    first,I used wxWidgets Frame to developchartDirectors;second,I have used wxDateTime convert to timeStamps。If i used XYchart Class that setLabels(xDataArray, "{value|hh:nn}"). it displays perfect.
it is my part demo:
        DoubleArray xDataArray = DoubleArray(m_timeDivStamps, m_nIndex);
DoubleArray avgPriceArray = DoubleArray(m_averagePrice, m_nPoints);
DoubleArray newPriceArray = DoubleArray(m_newPrice, m_nPoints);
DoubleArray volDataArray = DoubleArray(m_dealCount, m_nPoints);

financeChart = new FinanceChart(1680);
financeChart->setAxisOnRight(false);

timeDivChart = financeChart->addMainChart(650);
timeDivChart->xAxis()->setMargin(5, 1);//设置图表前后间距
//xyChart->setBackground(0x000000);//背景黑色
timeDivChart->yAxis()->setTickLength(0);//轴刻度长度为零
timeDivChart->xAxis()->setLabels(xDataArray, "{value|hh:nn}");
timeDivChart->xAxis()->setLabelStep(35);//设置间距
// 保证刻度增量至少60秒
timeDivChart->xAxis()->setMinTickInc(60);
financeChart->setData(xDataArray, newPriceArray, newPriceArray, newPriceArray, newPriceArray,volDataArray,0);
//financeChart->setPercentageAxis();
LineLayer *avgPriceLayer = financeChart->addCloseLine(0x0000FF);
avgPriceLayer->addDataSet(avgPriceArray, 0xFFB90F);//


XYChart *chart = financeChart->addVolIndicator(200, 0xFF0000, 0x00FF00, 0xFF0000);

  Re: Finance Chart how to display timeStamps
Posted by Peter Kwan on Jan-09-2019 14:34
Hi zdw,

Is the time interval for the chart very short (less a few minutes)? The FinanceChart will automatically determine the label spacing - from one label per year (for data that spans many years) down to one label per hour (for data that spans 1 day). If your data are very short (a few minutes), the FinanceChart may only produce very few or no labels.

The FinanceChart is release in source code in the "FinanceChart.h" file. You can set a breakpoint and single step into the "setXLabels" subroutine inside. The code basically use setLabels to set the labels, similar to your code. The code checks the total time range of the data, then determine to use different kind of label spacing. Using single-stepping, you can determine which type of labels it is trying to generate.

In our original "Interactive Finance Chart" sample code, if the time range is very short (like only contain data from 09:30 to 10:20, the code will insert empty points so that it covers the entire trading day (eg. 09:30 to 16:40). This is a common practice for many intraday chart - the timestamps cover at least 1 day, even if only a few minutes of data are available.

However, if you really need to plot a chart with a small time range, you may need to use your own setLabels routine.

Regards
Peter Kwan

  Re: Finance Chart how to display timeStamps
Posted by zdw on Jan-09-2019 15:10
Since the financial chart can automatically determine the label spacing,why I set timeStamps that it doesn't display . time interval More than one hour.

  Re: Finance Chart how to display timeStamps
Posted by Peter Kwan on Jan-10-2019 03:15
Hi zdw,

I read your code carefully again. I think I found the cause the issue. In a FinanceChart, you need to add the data first, then you can add the main chart and other indicators.

You may try:

    FinanceChart *financeChart = new FinanceChart(1680);
    // Add data first
    financeChart->setData(xDataArray, newPriceArray, newPriceArray, newPriceArray, newPriceArray,volDataArray,0);

    financeChart->setAxisOnRight(false);

    XYChart *timeDivChart = financeChart->addMainChart(650);
    timeDivChart->xAxis()->setMargin(5, 1);//设置图表前后间距
    //xyChart->setBackground(0x000000);//背景黑色
    timeDivChart->yAxis()->setTickLength(0);//轴刻度长度为零
    //financeChart->setPercentageAxis();
    LineLayer *avgPriceLayer = financeChart->addCloseLine(0x0000FF);
    avgPriceLayer->addDataSet(avgPriceArray, 0xFFB90F);//

    XYChart *chart = financeChart->addVolIndicator(200, 0xFF0000, 0x00FF00, 0xFF0000);

Hope this can help.

Regards
Peter Kwan