Set static/fix column width for StackedColumnSeries
Hello,
Let's say my horizontal axis is a datetime axis. If I have one column in every 10th minute the columns are thick. When I have one column in every minute the columns are thin.
I would want to set a static width for every column (let's say 10 pixel) and even if two columns would be too close to each other they could just overlap. Is that possible?
Thanks in advance!
Best regards,
Tamas.
We have analyzed your query and we can achieve your requirement “Set column width for pixel value” by workaround with help of CustomTemplate support for chart series. please find the code example below.
|
<syncfusion:SfChart.Resources>
<ResourceDictionary>
<DataTemplate x:Key="seriesTemplate">
<Canvas>
<Border Background="{Binding Interior}"
Canvas.Left="{Binding RectX}"
Canvas.Top="{Binding RectY}"
Width="10"
Height="{Binding Height}" />
</Canvas>
</DataTemplate>
</ResourceDictionary>
</syncfusion:SfChart.Resources>
<syncfusion:ColumnSeries x:Name="columnSeries"
YBindingPath="Value"
XBindingPath="XValue"
ItemsSource="{Binding Data1}"
CustomTemplate="{StaticResource seriesTemplate}">
</syncfusion:ColumnSeries> |
Output:
Please let us know if you have any concern.
Hi Yuvaraj Palanisamy,
Thank you, now the fixed width is working very well!
Sadly, now I have another issue. The chart is loading live data of the last one hour and if the chart contains only one element, the column is not visible, only after I add a second column to the chart.
The only thing I found is that if I change the Canvas.Left property of the custom template to 0 the column turns visible.
<Border Background="{Binding Interior}"
Canvas.Left="{Binding RectX}"
Canvas.Top="{Binding RectY}"
Width="12"
Height="{Binding Height}" />Only one record:
Three records: (same result with two records)
And after I change the Canvas.Left property:
<Border Background="{Binding Interior}"
Canvas.Left="0"
Canvas.Top="{Binding RectY}"
Width="12"
Height="{Binding Height}" />
Please help me solve this issue.
Thanks in advance!
Best regards,
Tamas
Hello Yuvaraj Palanisamy,
This is the xaml code of the chart that is shown on the pictures I attached earlier.
<sync:SfChart Height="163"
Margin="0,0,2,0">
<sync:SfChart.Resources>
<ResourceDictionary>
<DataTemplate x:Key="seriesTemplate">
<Canvas>
<Border Background="{Binding Interior}"
Canvas.Left="{Binding RectX}"
Canvas.Top="{Binding RectY}"
Width="8"
Height="{Binding Height}" />
</Canvas>
</DataTemplate>
</ResourceDictionary>
</sync:SfChart.Resources>
<sync:SfChart.PrimaryAxis>
<sync:DateTimeAxis Minimum="{Binding Start, UpdateSourceTrigger=PropertyChanged}"
Maximum="{Binding End, UpdateSourceTrigger=PropertyChanged}"
Interval="1"
Visibility="Visible"
LabelFormat="HH:mm" />
</sync:SfChart.PrimaryAxis>
<sync:SfChart.SecondaryAxis>
<sync:NumericalAxis Maximum="150"
Interval="50" />
</sync:SfChart.SecondaryAxis>
<sync:SfChart.Series>
<sync:StackingColumnSeries ShowTooltip="True"
SegmentColorPath="CycleTimeColor"
ItemsSource="{Binding HourlyData}"
XBindingPath="Date"
CustomTemplate="{StaticResource seriesTemplate}"
YBindingPath="Interval1" />
<sync:StackingColumnSeries ShowTooltip="True"
SegmentColorPath="IntervalColor"
ItemsSource="{Binding HourlyData}"
CustomTemplate="{StaticResource seriesTemplate}"
Label="Interval2"
XBindingPath="Date"
YBindingPath="Interval2" />
</sync:SfChart.Series>
</sync:SfChart>
Thanks in advance!
Best regards,
Tamas
Regards,
Hello Yuvaraj Palanisamy,
Thank you very much, I will track the private request then.
I marked your first reply to my original question as answer.
Best regards,
Tamas.
Thanks for the update, please let us know if need any further assistance.
Regards,
Saravanan.
On further analysis of your requirement “Single datapoint ColumnSeries with custom template does not show segment when we set DateTimeAxis with minimum and maximum property” is not an issue. When we set DateTimeAxis Minimum & Maximum property segment was rendered from the outside the chart area, hence RectX got the negative value. To overcome this, we would like to suggest that draw segment for the exact datapoint value in the sample level as per the following code example.
|
<DataTemplate x:Key="seriesTemplate">
<Canvas>
<Border Background="{Binding Interior}"
Canvas.Left="{Binding Converter={StaticResource segmentConverter}}"
Canvas.Top="{Binding RectY}"
Width="12"
Height="{Binding Height}" />
</Canvas>
</DataTemplate> |
|
public class SegmentValueConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var segment = value as Syncfusion.UI.Xaml.Charts.ColumnSegment;
var center = segment.RectX + (segment.Width) / 2 - (segment.Series as CustomColumnSeries).FixedPixelWidth / 2;
return center;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
- 8 Replies
- 3 Participants
- Marked answer
-
TK Tamas Kormos
- Sep 21, 2021 11:50 AM UTC
- Oct 12, 2021 03:20 PM UTC