For line chart can we plot lines from origin

1 Answer 84 Views
Charts
Ashwini
Top achievements
Rank 1
Iron
Iron
Ashwini asked on 28 Apr 2023, 09:35 AM

Hi,

I am trying to plot a line in chart from origin. In below image lines are starting from 8AM. can we plot 7AM at the origin of both axis, so all lines will start from origin 0. here I am trying to show data from 7AM to 8AM right now it is from 8AM. so at starting point it should be start from 0.
Is this possible with line chart

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 02 May 2023, 06:19 AM

Hi Aswini,

From what I understand, you want the lines to start from the vertical axis. If that is the case, you can set the "min" value of the ChartValueAxistItem to the time from where you want the axis to start:

I have created a very simple example demonstrating how the "min" property can be used for achieving the desired result:

    <ChartValueAxis>
      <ChartValueAxisItem min={1} />

If you have something different in mind, please do not hesitate to get back to us.

 

Regards,
Konstantin Dikov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 02 May 2023, 12:06 PM

Hi, same as you mentioned in above stackbliz example, but in my case different value I have used on x-axis
K9yqkg (forked) - StackBlitz
As I have implemented in above stackbliz example can we move 7AM to start of x axis.  As here I am showing ChartCategoryAxisItem can we implement same

Konstantin Dikov
Telerik team
commented on 03 May 2023, 02:13 PM

With the string values you can set the "min" property to "0.5", which will push the start point to the YAxis:

    <ChartCategoryAxis>
      <ChartCategoryAxisItem
        categories={categoriesVal}
        min={0.5}
        labels={{
          font: '9px Honeywell Sans Web',
        }}
      />

Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 05 May 2023, 10:43 AM

Thanks, it working as expected. One more thing I am trying to align shared tooltip at top position of chart. How can we do this. In below image I have marked it as yellow where I am trying to align. Can you suggest option for this one
Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 09 May 2023, 04:49 AM

K9yqkg (forked) - StackBlitz This I have this updated example with shared tooltip. Please reply asap.
Konstantin Dikov
Telerik team
commented on 09 May 2023, 05:17 AM

Hi Ashwini,

Although that there is no built-in way for changing the position of the tooltip in the requested way, you can use a custom solution with PopupPropsContext and a wrapping element around the Chart (although that this could be replaced with the Chart element). Using the popup context you can handle the onOpen and onPosition events to manually set the "top" position of the tooltip based on the position of the wrapping element within the page. I have created a simple example demonstrating such implementation:

Hope this helps.

Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 09 May 2023, 08:06 AM

Hi, 

I am trying with above suggestion this is not working with my code base, below error shown and also for document.querySelector also it throws error. Any other way to make it work

Konstantin Dikov
Telerik team
commented on 09 May 2023, 08:19 AM

Please share an example demonstrating the issue that you are facing with the suggested approach, so we can inspect it.
Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 09 May 2023, 12:54 PM | edited

K9yqkg (forked) - StackBlitz
I
n above example I have used tsx file instead of jsx. it is showing error for .style as shown in below image, but still it working here. In my codebase it is not at working 


In below image I have used !  to remove error, but my code crashes when I added above suggested changes



Konstantin Dikov
Telerik team
commented on 09 May 2023, 01:23 PM

You can explicitly cast the element to HTMLDivElement:

    let toolTip = document.querySelector('.custom-tooltip') as HTMLDivElement;    
    toolTip.style.top = offset + 'px';

As for why the code crashes in your example, it will be difficult to guess what could be causing it. I would suggest checking for any errors or ensuring that you have added the class name and the wrapping element in the same way as in the example. 

If the issue persists, please try to reproduce the issue in an example, so we can debug it locally.

 

Ashwini
Top achievements
Rank 1
Iron
Iron
commented on 10 May 2023, 05:31 AM | edited

Now it's working with above solution. Thanks:)
But for mobile view offset value not working properly. any other solution instead of using offset because offset is not working properly when page have scroll.
Konstantin Dikov
Telerik team
commented on 11 May 2023, 08:06 AM

The getBoundingClientRect returns the relevant position within the viewport, so changing the position of the popup element to fixed, should handle the scenario with the scrollbars:

            <style>
                .custom-tooltip{
                    position: fixed!important;
                }

Tags
Charts
Asked by
Ashwini
Top achievements
Rank 1
Iron
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or