原創|使用教程|編輯:郝浩|2013-02-21 10:19:47.000|閱讀 890 次
概述:在WPF圖表控件Chart FX使用方法系列中我們為大家介紹了一系列Chart FX for WPF的使用方法。有時候圖表圖例的尺寸將會約束到圖表,這個主要是因為會占用太多的空間,在今天的文章中,一起來探討幾個解決這個問題的方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在WPF圖表控件Chart FX使用方法系列中我們為大家介紹了一系列Chart FX for WPF的使用方法。有時候圖表圖例的尺寸將會約束到圖表,這個主要是因為會占用太多的空間,在今天的文章中,一起來探討幾個解決這個問題的方法。
風格化標題來模仿圖例的樣式:
在Chart FX for WPF中,標題都是全部可以樣式化的,雖然通常標題都是字符串,但是實際上你也可以在標題中使用任何的WPF 視覺效果,這種方法就有一個問題,你必須編寫很多關于標題的信息,比如說系列的數量、顏色等,這樣的話,將會導致很多不適用的且大數據量的代碼信息,而且將不會有高亮的效果。
在標題下方顯示圖例:
刪除圖例邊框,并將圖例的邊框停靠到頂部。
<cfx:Chart.Titles> <cfx:Title>Sales in 1998</cfx:Title> </cfx:Chart.Titles> <cfx:Chart.LegendBox> <cfx:LegendBox cfx:Chart.DockBorder="None" DockPanel.Dock="Top" /> </cfx:Chart.LegendBox>
值得注意的是,默認的類樣式會在區域空間外較大的繪制主要的標題,但是如果你比較喜歡將這兩個放在一起,你可以修改圖例中的目標面板,如果沒有產生想要的效果,你可以更新生成的方式:
<cfx:Chart.LegendBox> <cfx:LegendBox cfx:Chart.DockBorder="None" DockPanel.Dock="Top" cfx:Chart.TargetPanel="Titles-0" /> </cfx:Chart.LegendBox>
將標題和圖例放在一行中:
如果序列的數量比較小的話,就可以將標題和圖例結合起來:
<Style x:Key="LegendTitleStyle" TargetType="{x:Type ItemsControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" IsItemsHost="True" VerticalAlignment="Top" /> <TextBlock VerticalAlignment="Top" Text="{Binding Path=Tag}"/> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> <DataTemplate x:Key="LegendTitleItem"> <StackPanel Orientation="Horizontal"> <StackPanel.Resources> <cfxConverters:BoolToVisibilityConverter x:Key="BoolToVisibility"/> </StackPanel.Resources> <StackPanel VerticalAlignment="Top" x:Name="textAndLine"> <Border Background="Transparent"> <ContentControl IsHitTestVisible="false" Content="{Binding Path=Content}" ContentTemplate="{Binding Path=ContentTemplate}" Foreground="{Binding Path=Foreground}" FontFamily="{Binding Path=FontFamily}" FontSize="{Binding Path=FontSize}" FontStyle="{Binding Path=FontStyle}" FontWeight="{Binding Path=FontWeight}"/> </Border> <Rectangle Fill="{Binding Path=Stroke}" Height="3"/> </StackPanel> <TextBlock Text=" "/> <TextBlock Text="Vs " IsHitTestVisible="false" Visibility="{Binding Path=LastInGroup, Converter={StaticResource BoolToVisibility}, ConverterParameter=false}"/> </StackPanel> <DataTemplate.Triggers> <DataTrigger Binding="{Binding Path=Dimmed}"> <DataTrigger.Value> <sys:Boolean>True</sys:Boolean> </DataTrigger.Value> <Setter Property="Opacity" Value="0.25" TargetName="textAndLine" /> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> <cfx:Chart.LegendBox> <cfx:LegendBox cfx:Chart.DockBorder="None" DockPanel.Dock="Top" Tag="Sales in 1998" ContainerStyle="{StaticResource LegendTitleStyle}"> <cfx:LegendBox.ItemAttributes> <cfx:LegendItemAttributes cfx:LegendItemAttributes.LegendItemType="Series" Template="{StaticResource LegendTitleItem}"/> </cfx:LegendBox.ItemAttributes> </cfx:LegendBox> </cfx:Chart.LegendBox>
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件