RadChart CustomGridLine

10 posts, 1 answers
  1. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 14 Mar 2011 Link to this post

    Hi,

    Is it possible to set the YIntercept of a CustomGridLine in the RadChart DataBound event?

    Thanks,
    Amy
  2. Answer
    Missing user
    Missing user avatar

    Posted 17 Mar 2011 Link to this post

    Hi Amy,

    You can achieve this by getting the CustomGridLine through the Annotations collection, for example:

    <telerik:RadChart.DefaultView>
        <telerik:ChartDefaultView>
            <telerik:ChartDefaultView.ChartArea>
                <telerik:ChartArea>
                    <telerik:ChartArea.Annotations>
                        <telerik:CustomGridLine
                                        YIntercept="2"
                                        Stroke="Red"
                                        StrokeThickness="2" />
                    </telerik:ChartArea.Annotations>
                </telerik:ChartArea>
            </telerik:ChartDefaultView.ChartArea>
        </telerik:ChartDefaultView>
    </telerik:RadChart.DefaultView>

    private void radChart_DataBound(object sender, ChartDataBoundEventArgs e)
    {
        (radChart.DefaultView.ChartArea.Annotations[0] as CustomGridLine).YIntercept = 5;
    }

    Another way to set the YIntercept in the DataBound event is to create the CustomGridLine from the code behind:
    private void radChart_DataBound(object sender, ChartDataBoundEventArgs e)
    {
        CustomGridLine gridline = new CustomGridLine();
        gridline.YIntercept = 5;
        gridline.Stroke = new SolidColorBrush(Colors.Red);
        gridline.StrokeThickness = 2;
        radChart.DefaultView.ChartArea.Annotations.Add(gridline);
    }

    I hope this helps.

    All the best,
    Polina
    the Telerik team
  3. DevCraft banner
  4. Amy
    Amy avatar
    27 posts
    Member since:
    Sep 2010

    Posted 17 Mar 2011 Link to this post

    Thank you Polina.

    I actually tried the first method you described originally by setting the CustomGridLine in the XAML file and then setting the YIntercept in the DataBound event.  However, I was trying to access the CustomGridLine using the Name property of the CustomGridLine rather than an index in the Annotations collection - which did not work.

    I then used the second method you described creating the CustomGridLine in code which worked just fine.

    However, I've now decided to revert back to the first method since I'd rather define my controls in the XAML file.

    Thanks again,
    Amy
  5. Missing user
    Missing user avatar

    Posted 22 Mar 2011 Link to this post

    Hi Amy,

    As I mentioned in the previous post, when you define CustomGridLine in the XAML file, the available approach to access the CustomGridLine in the DataBound event is via the Annotations collection.

    All the best,
    Polina
    the Telerik team
  6. Dan
    Dan avatar
    70 posts
    Member since:
    Mar 2007

    Posted 11 Oct 2011 Link to this post

    Hi Polina

    I need your help on this matter:
    For current WPF project I must create a report with an embedded Chart which must display horizontal gridlines (corresponding to Y axis) for certain values (not major or minor gridlines!). Please see attached file.

    Short explanations: on X axis: time, on Y axis: weight (kg)

    After one working day I couldn't find any solution.
    Any help will be appreciated (an example would be great).

    Thanks a lot!!
    Dan
  7. Sia
    Admin
    Sia avatar
    667 posts

    Posted 12 Oct 2011 Link to this post

    Hello Michael,

    Please check the following example. The line you see there is a custom gridline. The same example (with shared source code) is available in our demos for WPF.

    Best wishes,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Dan
    Dan avatar
    70 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2011 Link to this post

    Hi Sia

    As I said in previous message Chart is embedded into a report.
    Report is loaded into WPF project.

    I've tried to find a way to implement your example in code because as you can know I don't have access to xaml there :).
    Can you provide me with another example focused on this scenario?

    I know this is not the right place for this posting because it's focused on WPF, but here I found similar questions; in Reports support I couldn't found anything.

    Thanks a lot!
  9. Sia
    Admin
    Sia avatar
    667 posts

    Posted 17 Oct 2011 Link to this post

    Hello Dan,

    First of all, please excuse me for the misunderstanding. Since you are using Reporting for WPF, there you can use only marked zones, but not grid lines. The only possible workaround which comes to my mind is to set a thin marked zone for every custom gridline.

    Regards,
    Sia
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  10. Dan
    Dan avatar
    70 posts
    Member since:
    Mar 2007

    Posted 18 Oct 2011 Link to this post

    Hi Sia

    Your sugestion it solved my problem for the moment.
    Thank you a lot!


    Dan
  11. Asawin
    Asawin avatar
    3 posts
    Member since:
    Nov 2012

    Posted 20 Nov 2012 Link to this post

    i would like to display graph on yxis  like image below can I do that please advise to me

     

Back to Top
DevCraft banner