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

Binding XLabelItem

3 Answers 85 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Yves
Top achievements
Rank 1
Yves asked on 05 Aug 2010, 04:19 PM
Hi,

Here is a new problem, but more simple than the first

I would like to bind a property which return a  List<string> to XLabel of my Chart. (If it's posible by XAML code)

Here is two screenshot of what i would like to get :

avant.png is what I've got with classic chart
apres.png is what I expect.

I'm using RadControls for WPF Q2 2009

Thank's.

3 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 09 Aug 2010, 03:08 PM
Hello Yves,

Binding axis item label values can be achieved if you are using the control in categorical mode.

Hope this helps.


Kind regards,
Freddie
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Yves
Top achievements
Rank 1
answered on 09 Aug 2010, 04:29 PM
Hi,

Thanks you. It seems to be the solution to my problem. But actually I'm not able to apply it to my application.

I've changed the XAML code and now my chart display nothing (well just a line at y=0 for each x);

here is my code :

<telerik:RadChart x:Name="RadChart1" telerik:StyleManager.Theme="Office_Black"  Grid.Row="1" Height="193" Width="372" Grid.Column="1" ItemsSource="{Binding NbHitLus}" DataContext="{Binding}">         
    <telerik:RadChart.DefaultView>
        <telerik:ChartDefaultView>
            <telerik:ChartDefaultView.ChartArea>
                <telerik:ChartArea LegendName="CustomLegend" Name="chArea" NoDataString="Aucune données">
                    <telerik:ChartArea.AxisX>
                        <telerik:AxisX MajorGridLinesVisibility="Collapsed"
                                       Title="Minutes" 
                                       AutoRange="True" IsZeroBased="True" LabelStep="5" LabelRotationAngle="45"/>
                    </telerik:ChartArea.AxisX>
                    <telerik:ChartArea.AxisY>
                        <telerik:AxisY MajorGridLinesVisibility="Collapsed"
                                       MinorTicksVisibility="Visible"
                                       Title="Hits Lus" AutoScale="True" />
                    </telerik:ChartArea.AxisY>
                </telerik:ChartArea>
            </telerik:ChartDefaultView.ChartArea>
            <telerik:ChartDefaultView.ChartLegend>
                <telerik:ChartLegend Visibility="Collapsed" x:Name="CustomLegend" UseAutoGeneratedItems="True" Width="0">
                    <telerik:ChartLegend.Header>Custom legend header</telerik:ChartLegend.Header>
                </telerik:ChartLegend>
            </telerik:ChartDefaultView.ChartLegend>
            <telerik:ChartDefaultView.ChartTitle>
                <telerik:ChartTitle HorizontalAlignment="Center" >
                    <TextBlock TextAlignment="Center">
                        <TextBlock Style="{StaticResource textCache}">
                            <TextBlock>Prog : </TextBlock><TextBlock Text="{Binding infoProg}" Margin="4,0,0,0"/>
                        </TextBlock>
                        <LineBreak/>
                        <TextBlock Margin="-8,0,0,0">Numéro collecteur :</TextBlock>
                        <TextBlock Text="{Binding IdCollect}"/>
                        <TextBlock Padding="10,0,0,0" Style="{StaticResource textCache}">Numéro log :</TextBlock>
                        <TextBlock Text="{Binding InfoLogs}" Style="{StaticResource textCache}"/>
                    </TextBlock>
                </telerik:ChartTitle>
            </telerik:ChartDefaultView.ChartTitle>
        </telerik:ChartDefaultView>
    </telerik:RadChart.DefaultView>
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping>
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False">   
                </telerik:LineSeriesDefinition>
            </telerik:SeriesMapping.SeriesDefinition>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
</telerik:RadChart>

So it loses ItemSource binding from Chart, but I don't know how to set kind of ItemSource to my LineSeriesDefinition. In addition from this code I don't know how to bind my string collection to my chart. i've seen thaht it's trough ItemsMapping in MappingSeries but I can't find it in XAML code. Here is the import :


For information, I'm using MVVM pattern and this chart is an UserControl, so i didn't have any behind code, so if it's posible I would like to have a "XAML solution". It's not an obligation of course ^^

Thank you for helping :) .

PS : And once again sorry for my bad english
0
Yves
Top achievements
Rank 1
answered on 11 Aug 2010, 08:33 AM
Well, now i've got this code which seems to be better than the first :
<telerik:RadChart.SeriesMappings>
                   <telerik:SeriesMapping>
                       <telerik:SeriesMapping.ItemMappings>
                           <telerik:ItemMapping DataPointMember="XCategory" diag:PresentationTraceSources.TraceLevel="High" FieldName="PublicationCollecteurVM.Heures">
                           </telerik:ItemMapping>
                           <telerik:ItemMapping DataPointMember="YValue" diag:PresentationTraceSources.TraceLevel="High" FieldName="PublicationCollecteurVM.NbHitsLus">
                           </telerik:ItemMapping>
                       </telerik:SeriesMapping.ItemMappings>
                   </telerik:SeriesMapping>
               </telerik:RadChart.SeriesMappings>
               <telerik:RadChart.DefaultSeriesDefinition>
                   <telerik:SplineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False">
                   </telerik:SplineSeriesDefinition>
               </telerik:RadChart.DefaultSeriesDefinition>

BUT, XCategory dosen't display my string collection but strange values (Actually it displays Y Value on X Label). In addition, some times i've got "out of range" bug^.

My application is like that :

One chart is binded to ONE object (through DataContext), ItemsSource is binded with a property of this object (List<int>).

Thank's :)

EDIT : It's fixed !! :) I've add new class which contain X (string) and Y (int) and in my ChartViewModel, i've got list of this class. ItemsSource of my Chart is the list of this. Thank you for your help !!


 
Tags
Chart
Asked by
Yves
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Yves
Top achievements
Rank 1
Share this question
or