How would go about setting the x and y axis titles. These are captions below the ticks (ie. Years)?
Thanks,
Steve
axis titles are not yet a feature of the xamchart. you can request features here: http://devcenter.infragistics.com/protected/requestfeature.aspx
here's how you can override the control template to include textblocks at the left and bottom of the control. you can use these as your axis titles.
<igCA:XamChart Height="300" Width="300">
<igCA:XamChart.Template>
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="25" />
</Grid.RowDefinitions>
<ContentPresenter Name="PART_Default_Chart" Grid.Row="0" Grid.Column="1" />
<TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" TextAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90" />
</TextBlock.LayoutTransform>
Left Title
</TextBlock>
<TextBlock Grid.Row="1" Grid.ColumnSpan="2" TextAlignment="Center">Bottom Title</TextBlock>
</Grid>
</ControlTemplate>
</igCA:XamChart.Template>
</igCA:XamChart>
how can I do this with C# code?
Do you want to be able to define the control template in C# or just assign it in C#? If its the latter you can just define that control template in your xaml resources (maybe in App.xaml?). And then assign it using something like xamChart1.Template = Resources["chartTemplate"]; where chartTemplate is the key you assigned to the resource.
If you want to create the entire template in code, then you should either:
1) Use that xaml as a string in your application and use XamlReader to hydrate it. Then assign it to the template property of the chart.
2) Create the template programmatically using FrameworkElementFactory, then assign it.
The second option there is more complex. A control template must create its content many times, and each time the content must be a distinct instance, thus it is defined as a factory that produces a new instance of the content on demand. When you define one in xaml, the transformation from an "instance" of what you want to create to a factory that produces an instance of the described is done automatically, so things are a bit more complicated if you want to do it by hand. What is the reason you want to define this in C#?
-Graham
Another interesting way of moving from a programatically created control tree to turning it into a ControlTemplate might be to:
Hope that helps!
This should obviously be a native feature of the XamChart
Why aren't such labels provided in the xamchart? A caption is provided, why not these labels?
thanks, now it really looks nice.
When you set the chart's template the theme change is not allowed to override the chart's template, so some details of the neon theme at the level of the chart are lost. You can adjust for this by reconciling the template you are specifying with the neon theme's template. Here's the modified version:
<Window.Resources> <SolidColorBrush x:Key="CaptionForegroundBrush" Color="#FFFFFFFF"/> <Style x:Key="captionStyle" TargetType="TextBlock"> <Setter Property="Foreground" Value="{StaticResource CaptionForegroundBrush}"/> <Setter Property="FontFamily" Value="/xamFeatureBrowserResources;Component/fonts/#Avenir"/> <Setter Property="FontSize" Value="16"/> <Setter Property="FontWeight" Value="Bold" /> </Style> <ControlTemplate x:Key="chartTemplate" TargetType="igChart:XamChart"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="0,0,0,0"> <Grid > <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ContentPresenter Name="PART_Default_Chart" Grid.Row="0" Grid.Column="1" /> <TextBlock Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" TextAlignment="Center" Style="{StaticResource captionStyle}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:AxisInfo.YAxisTitle)}"> <TextBlock.LayoutTransform> <RotateTransform Angle="90" /> </TextBlock.LayoutTransform> </TextBlock> <TextBlock Grid.Row="1" Grid.ColumnSpan="2" Style="{StaticResource captionStyle}" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(local:AxisInfo.XAxisTitle)}" TextAlignment="Center" /> </Grid> </Border> </ControlTemplate> </Window.Resources>
Hope this helps!
Hi,
thank you very much for the example. I got it working. Unfortunately I still have the problem with the theme of the XamGraph. As you can see in the attached image, it's not really the Neon theme. In the second image it's a bit like the neon theme, but the backgroundcolor is not correct.
Because of the white background, I cannot see the caption. Of cause I can set the color of it manually, but I would like to have the background just like the neon theme.
As I am no expert in Templates, maybe you can give me an hint how to place the axis information more near to the axis. I would like to have the x-axis info on the bottom right and the y-axis on the top left of the graph.
Thanks a lot!
Gawain