This is a migrated thread and some comments may be shown as answers.

[Solved] Spline chart don show vb .net

3 Answers 76 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
armando hernandez
Top achievements
Rank 1
armando hernandez asked on 29 Jan 2013, 01:46 AM

This example i downloaded from this web in c# and Works fine, but the problem is when i translate it to vb .NET and dont show anything, somebody who wants help me?

XAML

<Page
    x:Class="App1.MainPage"
    xmlns:local="using:App1"
    xmlns:telerik="using:Telerik.UI.Xaml.Controls.Chart"
    mc:Ignorable="d">
 
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
 
        <telerik:RadCartesianChart x:Name="Chart" PaletteName="DefaultDark">
            <telerik:RadCartesianChart.DataContext>
                <local:DataChartObject/>
            </telerik:RadCartesianChart.DataContext>
            <telerik:RadCartesianChart.VerticalAxis>
                <telerik:LinearAxis></telerik:LinearAxis>
            </telerik:RadCartesianChart.VerticalAxis>
            <telerik:RadCartesianChart.HorizontalAxis>
                <telerik:DateTimeCategoricalAxis LabelFormat="{}{0:dd-MMM}" DateTimeComponent="Day"/>
            </telerik:RadCartesianChart.HorizontalAxis>
 
            <telerik:AreaSeries ItemsSource="{Binding Data1}" CombineMode="Stack">
                <telerik:AreaSeries.ValueBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Porcentaje"></telerik:PropertyNameDataPointBinding>
                </telerik:AreaSeries.ValueBinding>
                <telerik:AreaSeries.CategoryBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="DiaMes"></telerik:PropertyNameDataPointBinding>
                </telerik:AreaSeries.CategoryBinding>
            </telerik:AreaSeries>
            <telerik:AreaSeries ItemsSource="{Binding Data2}"  CombineMode="Stack">
                <telerik:AreaSeries.ValueBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="Porcentaje"></telerik:PropertyNameDataPointBinding>
                </telerik:AreaSeries.ValueBinding>
                <telerik:AreaSeries.CategoryBinding>
                    <telerik:PropertyNameDataPointBinding PropertyName="DiaMes"></telerik:PropertyNameDataPointBinding>
                </telerik:AreaSeries.CategoryBinding>
            </telerik:AreaSeries>
        </telerik:RadCartesianChart>
         
    </Grid>
</Page>


XAML.VB

' La plantilla de elemento Página en blanco está documentada en http://go.microsoft.com/fwlink/?LinkId=234238
 
''' <summary>
''' Página vacía que se puede usar de forma independiente o a la que se puede navegar dentro de un objeto Frame.
''' </summary>
Public NotInheritable Class MainPage
    Inherits Page
 
    ''' <summary>
    ''' Se invoca cuando esta página se va a mostrar en un objeto Frame.
    ''' </summary>
    ''' <param name="e">Datos de evento que describen cómo se llegó a esta página. La propiedad Parameter
    ''' se usa normalmente para configurar la página.</param>
    Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
        Me.DataContext = New DataChartObject()
    End Sub
 
End Class


CHARTOBJECT CLASS

Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
 
Public Class DataChartFunctions
 
    Public DiaMes As DateTime
    Public Porcetaje As Double
    Private Shared r As Random = New Random()
 
 
    Public Shared Function GetDataFisico() As List(Of DataChartFunctions)
 
        Return New List(Of DataChartFunctions)({
            New DataChartFunctions With {.DiaMes = DateTime.Now, .Porcetaje = r.Next(10, 40)},
            New DataChartFunctions With {.DiaMes = DateTime.Now.AddDays(-1), .Porcetaje = r.Next(10, 40)},
            New DataChartFunctions With {.DiaMes = DateTime.Now.AddDays(-2), .Porcetaje = r.Next(10, 40)},
            New DataChartFunctions With {.DiaMes = DateTime.Now.AddDays(-3), .Porcetaje = r.Next(10, 40)},
            New DataChartFunctions With {.DiaMes = DateTime.Now.AddDays(-4), .Porcetaje = r.Next(10, 40)},
            New DataChartFunctions With {.DiaMes = DateTime.Now.AddDays(-5), .Porcetaje = r.Next(10, 40)}
            })
 
    End Function
 
 
End Class
 
 
Public Class DataChartObject
 
    Public Sub New()
        LoadData()
    End Sub
 
    Private Sub LoadData()
        Data1 = DataChartFunctions.GetDataFisico()
        Data2 = DataChartFunctions.GetDataFisico()
    End Sub
 
    Public Data1 As IEnumerable
    Public Data2 As IEnumerable
 
End Class

3 Answers, 1 is accepted

Sort by
0
armando hernandez
Top achievements
Rank 1
answered on 29 Jan 2013, 01:54 AM
From here (http://www.telerik.com/community/forums/metro/chart-xaml/databinding-radcartesianchart-areaseries.aspx
) i downloaded the example, is the second attached file in the post. In my version in vb .net don't show any error but also don't show any data. Help.
0
Ivaylo Gergov
Telerik team
answered on 29 Jan 2013, 04:18 PM
Hello Armando,

Thank you for your interest in our suite.

I reproduced the scenario from the given code snipped and it seems that you are trying to bind to a public field which is not supported by the platform. So, you need to declare a public properties like this:
Public Property Data1ToBind() As IEnumerable
        Get
 
            Return Data1
 
        End Get
        Set(value As IEnumerable)
            Me.Data1 = value
        End Set
    End Property
 
    Public Property Data2ToBind() As IEnumerable
        Get
 
            Return Data2
 
        End Get
        Set(value As IEnumerable)
            Me.Data2 = value
        End Set
    End Property

Then you need to reflect this change in in AreaSeries.ItemsSource binding:
<telerik:AreaSeries ItemsSource="{Binding Data1ToBind}"  CombineMode="Stack">
<telerik:AreaSeries ItemsSource="{Binding Data2ToBind}"  CombineMode="Stack">

I have also noticed that in the xaml page you are trying to bind to Porcentaje:

<telerik:PropertyNameDataPointBinding PropertyName="Porcentaje"></telerik:PropertyNameDataPointBinding>

But in the DataChartFunctions class you have declared a field Porcetaje (without "n")

Public Porcetaje As Double

I suggest this is a typo and you need to fix it.

I also recommend you to sort the data before you pass it to the chart as it expects to receive it in ascending order.

I hope this information is useful. If you have any other questions do not hesitate to write us again.

 

Greetings,
Ivaylo Gergov
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
armando hernandez
Top achievements
Rank 1
answered on 29 Jan 2013, 05:01 PM
thank you very much, i'm a novice in .NET but i try my best, thanks and have a good day
Tags
Chart for XAML
Asked by
armando hernandez
Top achievements
Rank 1
Answers by
armando hernandez
Top achievements
Rank 1
Ivaylo Gergov
Telerik team
Share this question
or