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

Message ListMessage List     Post MessagePost Message

  Highlighting a line in a chart
Posted by Dave on May-18-2020 05:14
Hello All!

I am new to the library and I am trying to implement a chart containing several lines where I want to hover or double-click on a line and highlight the whole line, display it's value at the point selected and highlight the value on the x axis, and, display the values at intersection of the line with Y axis.

Any examples doing that? Any ideas??

Many thanks!

Dave

  Re: Highlighting a line in a chart
Posted by Peter Kwan on May-18-2020 21:47
Hi Dave,

I can provide an example to you, but I would need more information on your requirements.

Would you mind to clarify which programming language and GUI framework or web framework you are using? (Eg. C++ MFC, C# Windows Forms, VB ASP.NET, etc).

What type of line are you plotting? Is it a regular line chart, like the lines in a MultiLine Chart:

https://www.advsofteng.com/doc/cdnet.htm#multiline2.htm

Or it is a trend line in which ChartDirector may extend it until it reaches the border of the plotarea:

https://www.advsofteng.com/doc/cdnet.htm#scattertrend.htm

There are several examples in ChartDirector that displays the data point at the mouse position

https://www.advsofteng.com/doc/cdnet.htm#tracklabel.htm
https://www.advsofteng.com/doc/cdnet.htm#trackaxis.htm

In the examples that come with ChartDirector, it displays the "data points". A line chart is obtained by joining the data points. When you click on a line, you may not be clicking on a data point, but somewhere between two data points. In the examples in ChartDirector, we will simply snap to the nearest data point.

If you can provide more details, I can modify one of the examples to better fit your requirements.

Regards
Peter Kwan

  Re: Highlighting a line in a chart
Posted by Dave on May-22-2020 22:32

I am developing my own financial chart, computing my own indicators, in C++ QT5 where I need to add several lines that get updated with real time data

So I guess this at this point this is two questions in one:

The first on how to hover or click on a line and have the whole line in the chart highlight, and second how to update the graph with real time data.

I would also like to add a symbol at certain places and have the symbol move with the chart as it adds new real time data.

Many thanks!!

Dave

  Re: Highlighting a line in a chart
Posted by Peter Kwan on May-24-2020 03:25
Attachments:
Hi Dave,

ChartDirector charts accept data stored in array variables. For real time charts, you just need to update your data arrays in real time and redraw the chart. In this way, the chart will also update in real time. This works for all chart types, including financial charts. You can refer to the real time chart examples that come with ChartDirector as reference.

A real time chart can be always moving. The line may scroll when new data comes in, and the y-axis scale can change. I am thinking, it may not be easy to "hover" over a particular line as the line is constantly moving. So in the attached code, I use mouse click to select the line. As a line can be very thin and hard to click, the code assumes the mouse clicks on the line if it is within 3 pixels from the line.

If you look at the track cursor sample code, ChartDirector can find the data x position that is closest to the mouse x position. I simply iterate all the data sets so I can get the y position as well, and determine if the mouse is close enough to the line. Then I save the data set name.

In another part of the code, there is a subroutine that will set the line width to 3 for a data set with a given name. This can be used to highlight the line.

You can add symbols at certain place by using scatter layers. In standard financial charts, the data arrays for everything are of the same length. So if you have 100 candlesticks, the symbol array should also be 100 in size. The array can be initialized to contain Chart::NoValue, so there would be no symbol initially. Your code can then put data values at the positions that have symbols. This data array can be updated just like other data arrays in your code.

In the attached zip file, I have included two Qt examples. One is modified from the "Realtime Chart with Track Line" sample code, the other from the "Finance Chart Track Line" sample code. You can click on the line to highlight it.

Regards
Peter Kwan
qtdemo_click_highlight.zip
qtdemo_click_highlight.zip

35.49 Kb

  Re: Highlighting a line in a chart
Posted by Dave on Jun-01-2020 16:01
Hi Peter!

I truly appreciate your support and help!

I'll be working on this for the next few days.

I must say I am impressed by the easiness of integrating your software, and by the professional grade of the code.

Many thanks!

Dave

  Re: Highlighting a line in a chart
Posted by Dave on Jun-03-2020 12:52
Hi Peter,

I tried to use the modified trackfinance.cpp, but I get an undefined reference error on highlightLine, in the following code:

    if (highlightLineName.size() > 0)
        highlightLine(c, highlightLineName.c_str());


I reinstalled the libs but they are the same version from nov 2019....

Thanks,

Dave

  Re: Highlighting a line in a chart
Posted by Peter Kwan on Jun-03-2020 13:10
Attachments:
Hi Dave,

Sorry for this problem. The highlightLine is a function to highlight a line. During development, I tried several highlightLine functions, then I deleted all of them except the one that works best. However, for one of the deleted highlightLine, I forgot to delete the declaration in the header file. So the code contains the declaration but not implementation of a function that should be deleted, causing this issue.

To solve the problem, go to the "trackfinance.h" header file, and delete the highlightLine method there.

I have updated the zip file as attached to contain the corrected "trackfinance.h". You may use the new download if you do not bother to delete the highlightLine function in the header file.

Regards
Peter Kwan
qtdemo_click_highlight_updated.zip
qtdemo_click_highlight_updated.zip

35.47 Kb