GetGraphSegmentInfo problem

A forum dedicated to WinForms version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
fredd41
Posts: 113
Joined: Fri Sep 05, 2014 6:46 pm

GetGraphSegmentInfo problem

Post by fredd41 » Fri Mar 02, 2018 8:21 pm

hi

it is possible to get segment informations while an chart update ?

example:

chart.beginupdate
' .... modify segments (ex. remove 2 segments)
Dim t() As Single = Chart.ViewXY.GetGraphSegmentInfo.SegmentTops ' wrong values
myUserControl3.top = t(2) ' wrong value
chart.endupdate
Dim t() As Single = Chart.ViewXY.GetGraphSegmentInfo.SegmentTops ' right values
myUserControl3.top = t(2) ' right value

it was very useful to get segment info while updating a chart to resize and replace other controls before endupdate.

fred

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: GetGraphSegmentInfo problem

Post by ArctionKestutis » Mon Mar 05, 2018 7:54 am

Hi,

No, it is not possible to have fast rendering and on-fly update of all drawing data. That is trade of. Most of LightningChart properties are interconnected: very often you need partial or full refresh for changes propagate through all chart.
Typical recommendation in this situation - use Chart.AfterRendering event. Just subscribe to this event whenever you need to get newest Chart's info and modify relevant properties in the event handler (don't forget to unsubscribe from Chart.AfterRendering event - not to end-up with infinite loop). This way you should be able to get final look with 2 refresh/update cycles.

All the best.

fredd41
Posts: 113
Joined: Fri Sep 05, 2014 6:46 pm

Re: GetGraphSegmentInfo problem

Post by fredd41 » Tue Mar 06, 2018 3:58 am

I would like to move and resize my user controls before the endupdate() function.

Can you tell me how you calculate the height and top values of each segment ?
Is it possible to calculate these values with these parameters :

Chart.Height
Chart.ViewXY.Margins.Vertical
Chart.Margin.Vertical
Chart.Padding.Vertical
Chart.ViewXY.Yaxes.Count
Chart.ViewXY.AxisLayout.SegmentsGap

For testing, I'm tring to figure out how you get these values :

For Each y In Chart.ViewXY.YAxes
Dim t, h As Single
y.GetGraphSegmentTopAndHeight(t, h)
Console.WriteLine("top " & t & " height " & h)
Next
Console.WriteLine("total " & Chart.ViewXY.GetGraphSegmentInfo.GraphHeight)
dim gapsHeight as single = (Chart.ViewXY.Yaxes.Count - 1) * Chart.ViewXY.AxisLayout.SegmentsGap
Console.WriteLine("my segment height " & (Chart.ViewXY.GetGraphSegmentInfo.GraphHeight - gapsHeight) / Chart.ViewXY.Yaxes.Count)

output:
top 34 height 86
top 134 height 86
top 234 height 87
top 335 height 86
top 435 height 87
top 536 height 86
top 636 height 88
total 690
my segment height 86.57143

Can you tell how to get the height values with equations?

It would be really appreciated.
thanks
fred

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: GetGraphSegmentInfo problem

Post by ArctionKestutis » Tue Mar 06, 2018 9:13 am

Hi Fred,

I believe that is wrong approach. If you remove segment or resize app's window the information about segment need to be updated. The ViewXY.GetGraphSegmentInfo() will return wrong/old info until is repainted. Therefore, I suggested to use _chart.AfterRendering event, after which all Chart's properties and draw data are set correctly.

Although I don't recommend using it, the rough formula look like this

SegmentScreenHeight = SegmentHeightProperty / SumOfHeightProperties * ChartScreenHeight + 0.5 (and Cast to Integer),

where ChartScreenHeight is total chart's Height excluding margins and gaps. In addition, last segments take remaining available area.

As you see some rounding is unavoidable and if you not tolerate few pixel off, don't use this approach.

All the best.

fredd41
Posts: 113
Joined: Fri Sep 05, 2014 6:46 pm

Re: GetGraphSegmentInfo problem

Post by fredd41 » Tue Mar 06, 2018 1:45 pm

what is the equation to get SegmentHeightProperty and SumOfHeightProperties ?

and where is the index in your equation ? because each segment has a different value

what do you mean by "last segments" ? the last, the last two, the last three ...?

ArctionKestutis
Posts: 552
Joined: Mon Mar 14, 2016 9:22 am

Re: GetGraphSegmentInfo problem

Post by ArctionKestutis » Tue Mar 06, 2018 2:23 pm

SegmentHeightProperty = AxisLayout.Segments.Height

Code: Select all

            for (int i = 0; i <= iLastSegmentIndex; i++)
            {
               SumOfHeightProperties += Segments[i].Height;
             }
The 'last' means the last Segment in the list (AxisLayout.Segments).

All the best.

Post Reply