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

Message ListMessage List     Post MessagePost Message

  How to show time in the X-axis instead of month / year
Posted by isan on Jul-19-2018 23:27
Hello, I use SimpleZoomScroll with qt language. I want to show the time in X-axis instead of the month / year. How can I do this?

  Re: How to show time in the X-axis instead of month / year
Posted by Peter Kwan on Jul-20-2018 05:17
Hi isan,

You can use Axis.setLabelFormat to format the x-axis labels. For example:

c->xAxis()->setLabelFormat("{value|hh:nn:ss}");

Hope this can help.

Regards
Peter Kwan

  Re: How to show time in the X-axis instead of month / year
Posted by isan on Jul-21-2018 22:32
I added what you said ÙˆIn drawChart function and
It shows me 00:00:00 forever on SimpleZoomScroll Line 94, using this line:

m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1), 86400);

It should be change?this loaded date for x-axis
I changed it to :

m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1,10,20,30), 86400);

But it did not make a difference!

  Re: How to show time in the X-axis instead of month / year
Posted by Peter Kwan on Jul-22-2018 17:30
Hi isan,

If you use the original random numbers, the time of days of all labels are 00:00:00. So if you use {hh:nn:ss}, it will only display 00:00:00 for all labels.

The labels depend on the time range. The random data contains 1827 days (5 years) of data, so the labels on the chart will be many days apart. For example, two labels may be 1 week apart, so it is normal the time part of the label is 00:00:00.

Also note that the labels depend on the "time range", not the individual time of the data points. You can look at the y-axis. The y-axis labels are 0, 50, 100, 150, .... You can see that the labels has no decimal place, even though all data points have decimal places. The same applies to the x-axis. Even if you set the timestamps to have hh:nn:ss, it does not mean the labels will have hh:nn:ss.

For your case, if you want to use the random number generator, the important thing is to set a short duration. If the time range is less than 1 day, the labels must have non-zero hh:nn:ss. For example:

m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1), 30);

Hope this can help.

Regards
Peter Kwan










c->xAxis()->setLabelFormat("{value|hh:nn:ss}");


isan wrote:

I added what you said ÙˆIn drawChart function and
It shows me 00:00:00 forever on SimpleZoomScroll Line 94, using this line:

m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1), 86400);

It should be change?this loaded date for x-axis
I changed it to :

m_timeStamps = m_ranSeries->getDateSeries(1827, Chart::chartTime(2007, 1, 1,10,20,30), 86400);

But it did not make a difference!

  Re: How to show time in the X-axis instead of month / year
Posted by isan on Jul-22-2018 23:03
thank you for your response,I set a short duration and now I can see the non-zero time,
If I have a QStringList of time can I use them to set for x-axis labels in this project?
QStringList timeList;
timeList<<"18:20:30"<<"18:21:32"<<"18:22:34"<<.......

I know the m_timeStamps is a double array  and cannot convert this(:) to double, do you have any suggestions?

  Re: How to show time in the X-axis instead of month / year
Posted by Peter Kwan on Jul-24-2018 02:41
Hi isan,

The m_timeStamps you mentioned are the x-coordinate of the data points, not the x-axis labels. In the sample code, the x-axis labels values are automatically determined by ChartDirector, depending on which part of the data are displayed (remember the chart can zoom and scroll so at any time only part of the data are displayed). The axis labels values may not be the same as the data points. For example, for the y-axis, the labels can be 0, 50, 100, 150, 200, 250, 300. However, there are no data point with the value 0 in the chart, and they are possibly no data point with the value 100 too. So the labels are not the same as the data points. The same applies to the x-axis.

If you are referring to the x-coordinates m_timeStamps, in the sample code, they represents date/time. Please refer to the following on how the date/time should be represented in ChartDirector.

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

The "18:20:30" is a text string,  not date/time to Qt or ChartDirector. If you must use text strings as representing date/time in human language, I suggest you to extract the hour, minute and second values out, then use Chart::chartTime to construct the chart time value. An example is:

QString test = "18:20:30";
std::vector<double> timeList;
timeList.push_back(Chart::chartTime(2018, 1, 1, test.midRef(0, 2).toInt(), test.midRef(3, 2).toInt(), test.midRef(6,2).toInt());

.... after adding all the values to timeList, the array is:

DoubleArray m_timeArray = DoubleArray(&(timeList[0]), timeList.size());

Regards
Peter Kwan

  Re: How to show time in the X-axis instead of month / year
Posted by isan on Aug-04-2018 23:51
I did not change this code to test it, when I run it
I receive these messages:

QObject::connect: No such slot SimpleZoomScroll::onMouseMovePlotArea(QMouseEvent*) in ../simplezoomscroll/simplezoomscroll.cpp:61
QObject::connect: No such slot SimpleZoomScroll::onMouseWheelChart(QWheelEvent*) in ../simplezoomscroll/simplezoomscroll.cpp:62


And when I use  scrolling and zooming in / out the app's  will  close and error is:

bash: line 1:  3055 Segmentation fault

Is that because of those messages?or the app not work with the touch screen?

  Re: How to show time in the X-axis instead of month / year
Posted by Peter Kwan on Aug-05-2018 23:16
Hi isan,

From your description, i assume you are using the original "Simple Zooming and Scrolling" sample code without any modification.

The "QObject::connect ..." messages have no effect. To confirm, please remove lines 61 and 62 from the code to see if it makes any difference.

From your previous posts, it seems you have successfully tried some of our zooming and scrolling sample code. Would you mind to clarify exactly what has changed that causes the code to crash? Also, would you mind to clarify how to make it crash? Is it when you use the mouse to drag on the chart, or when you use the finger to touch and drag on the chart? Or is it when you press the "Zoom In" or "Zoom Out" button?

In your message, the error is "bash: line 1:  3055 Segmentation fault". Are you running the program in the Qt IDE (eg. QT Creator)? If you are using a development environment, you should be able to single step the program or set break points to determine which line causes the segmentation fault.

Which operating system you are using? Are you compiling the program on the machine that you runs the program? Or are you compiling the program in one machine, and copy the EXE to another machine to run?

Regards
Peter Kwan