I draw line chart,the x-axis is always at the bottom ,how to set the x-axis in the middle(means y=0 is the x-axis)?

4 posts, 0 answers
  1. PEIYANG
    PEIYANG avatar
    65 posts
    Member since:
    Jul 2012

    Posted 21 Jul 2012 Link to this post

    I draw chart,the x-axis is always at the bottom (that is, if y is the negative that the horizontal axis is negative too ),how to set the x-axis in the middle(means y=0 is the x-axis),no matter y value is positive or negative number?
  2. Rosko
    Admin
    Rosko avatar
    137 posts

    Posted 25 Jul 2012 Link to this post

    Hello Peiyang,

    You can achieve the desired effect by setting the Minimum and Maximum properties of the Vertical Axis. If you want to have 0 right in the middle make sure that you have equal number of units from the zero to the minimum and maximum.
    <telerik:RadCartesianChart.VerticalAxis>
       <telerik:LinearAxis Minimum="-100" Maximum="100"/>
    </telerik:RadCartesianChart.VerticalAxis>


    Greetings,
    Rosko
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Michael
    Michael avatar
    3 posts
    Member since:
    May 2012

    Posted 12 Dec 2012 Link to this post

    Hi Rosko,

    I am having the same problem. But setting the Minimum and Maximum values does not solve my problem.

    Here is my code:
    <telerik:RadCartesianChart>
        <telerik:LineSeries ItemsSource="{Binding MyItems}" ValueBinding="Value"
                      CategoryBinding="Date" />
        <telerik:RadCartesianChart.HorizontalAxis>
            <telerik:CategoricalAxis ShowLabels="false" />
        </telerik:RadCartesianChart.HorizontalAxis>
        <telerik:RadCartesianChart.VerticalAxis>
            <telerik:LinearAxis Minimum="-100" Maximum="100"/>
        </telerik:RadCartesianChart.VerticalAxis>
    </telerik:RadCartesianChart>

    I have attached the resulting chart as an image.

    Best regards,
    Michael Hilus

    // Edit:
    Sorry, the picture of the chart is the second one.
  5. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 14 Dec 2012 Link to this post

    Hi Michael,

    If I fully understand the requirements, you need to show the horizontal axis always at the position of the 0 in the VerticalAxis. We do not offer such a functionality, the horizontal axis has a property VerticalLocation and you can chose either Top or Bottom. Perhaps you can take advantage of the annotations and show a line at the zero:
    <telerik:RadCartesianChart.Annotations>
      <telerik:CartesianGridLineAnnotation
        Axis="{Binding VerticalAxis, ElementName=cartesianChart1}"
        Value="0"  />

    This would produce result as in the attached image. Hope this helps.

    Regards,
    Petar Marchev
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top