I would like to position the marker label, that you see above, inside the columns. Is this possible? And, if so, I would like to be able to do this with code behind.
Hello flowerdj,
Here is a code sample:
<Grid> <Grid.Resources> <Style TargetType="igWebChart:ColumnChartDataPointTemplate"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="igWebChart:ColumnChartDataPointTemplate"> <Border Background="{TemplateBinding Fill}"> <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="White" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataPoint.Value}" /> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>
</Grid.Resources>
<igWebChart:XamWebChart> <igWebChart:XamWebChart.Series> <igWebChart:Series ChartType="Column" StrokeThickness="3"> <igWebChart:Series.DataPoints> <igWebChart:DataPoint Value="5" /> <igWebChart:DataPoint Value="6" /> <igWebChart:DataPoint Value="7" /> </igWebChart:Series.DataPoints> </igWebChart:Series> </igWebChart:XamWebChart.Series> </igWebChart:XamWebChart> </Grid>
Position the text anywhere you like.
I have attached a sample which sets the data point style of a series with the press of a button.
There is also some commented code which sets the template of only one data point for the series.
Hi Nikolay,
Can you please provide an example on how to accomplish marker label alignment of xamChart (WPF) in the middle of bar (column or stacked) from the code behind
Thank you,Iryna
Hello Iryna,
Thank you for your post. I have been looking into it and the sample Nikolay has provided and I created a new one in WPF based on his, but I bound the TextBlock in the DataPointTemplate to the ToolTip of the DataPoint, which is bound to its Value, because there is no access directly to the DataPoint’s Value. Please let me know if this helps you or you need further clarifications on this matter.
Looking forward for your reply.
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
Attached is a solution with DataTemplate and xamChart build in C# to position marker in the column center.
i = 0; foreach (Dundas.Utilities.ChartControl.DataPoint dp in series.Points) { dp.BorderColor = Color.FromArgb(255, 0, 0, 0); dp.BorderStyle = PointAttributes.LineStyle.Solid; dp.BorderWidth = 1; dp.LabelFormat = "n0"; if (dp.YValues[0] < 10) { dp.CustomAttributes = ("LabelStyle = Top"); } i++; }
Hi Stefan,
Thank you for ToolTip binding trick. I am trying to achieve in code behind the same you have done in xaml. Mainly because I build XamChart dynamically. However still no success - both approaches will be fine assign resource from xaml to the chart or building datatemplate in C#. Please see the attached project.