How to add point on each chart data point

8 posts, 0 answers
  1. berry
    berry avatar
    27 posts
    Member since:
    Jun 2015

    Posted 13 Jul 2015 Link to this post

    Please see my attach screenshot.

    I want to add little point over each point in my chart view

  2. berry
    berry avatar
    27 posts
    Member since:
    Jun 2015

    Posted 13 Jul 2015 Link to this post

    Please see this example: http://docs.roguewave.com/jviews/8.9/jviews-charts89/codefragments/chart/rendering-hint/data/sample.gif
  3. UI for WPF is Visual Studio 2017 Ready
  4. berry
    berry avatar
    27 posts
    Member since:
    Jun 2015

    Posted 13 Jul 2015 Link to this post

    BTW i want to add it via code behind

     

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 14 Jul 2015 Link to this post

    Hello Berry,

    You can use the PointTemplate property of the series to define its visual element. For example:
    <telerik:LineSeries.PointTemplate>
        <DataTemplate>
            <Ellipse Fill="Red" Width="10" Height="10" />
        </DataTemplate>
    </telerik:LineSeries.PointTemplate>
    To add this in code you can define the template in XAML and get it through the Resources' dictionary of the view:
    <Window.Resources>
        <DataTemplate x:Key="pointTemplate">
            <Ellipse Fill="Red" Width="10" Height="10" />
        </DataTemplate>
    </Window.Resources>

    series.PointTemplate = (DataTemplate)this.Resources["pointTemplate"];

    Or you can define the template as string and use the XamlReader.Parse() method.
    string pointTemplateString = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">"+
                          @"<Ellipse Fill=""Red"" Width=""10"" Height=""10"" /></DateTemplate>";

    series.PointTemplate = (DataTemplate)XamlReader.Parse(pointTemplateString);

    I hope this is useful.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. berry
    berry avatar
    27 posts
    Member since:
    Jun 2015

    Posted 16 Jul 2015 in reply to Martin Link to this post

    When i try the lase option using "define the template as string and use the XamlReader.Parse() method":

    string pointTemplateString = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">"+
                          @"<Ellipse Fill=""Red"" Width=""10"" Height=""10"" /></DateTemplate>";

    series.PointTemplate = (DataTemplate)XamlReader.Parse(pointTemplateString);

    XamlParseException occurred:

    A first chance exception of type 'System.Windows.Markup.XamlParseException' occurred in PresentationFramework.dll
    Additional information: The 'DataTemplate' start tag on line 1 position 2 does not match the end tag of 'DateTemplate'. Line 1, position 183.

     

     

  7. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 16 Jul 2015 Link to this post

    Hello,

    This is caused by a typo in my code snippet. The closing tag in the string should be </DataTemplate> instead of </DateTemplate>.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  8. berry
    berry avatar
    27 posts
    Member since:
    Jun 2015

    Posted 16 Jul 2015 in reply to Martin Link to this post

    OK that's works now.

    BTW how can i replave the "Red" with string of my own ? (i want each pointTemplateSeries i have will be the same color as my Series Stroke)

  9. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 20 Jul 2015 Link to this post

    Hello Berry,

    In order to do this you can just modify the string. Here is an example:
    string series1Color = "#FF0000";
    string series2Color = "Green";
     
    string series1pointTemplateString = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">"+
    @"<Ellipse Fill=""" + series1Color + """ Width=""10"" Height=""10"" /></DatаTemplate>";
                           
    string series2pointTemplateString = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">"+
    @"<Ellipse Fill=""" + series2Color + """ Width=""10"" Height=""10"" /></DatаTemplate>";

    I hope this helps.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready