Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to wrap legend items or show in multiple rows (Read 4350 times)
sami
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Jun 4th, 2020
how to wrap legend items or show in multiple rows
Jun 4th, 2020 at 8:52am
Print Post  
hi all,
i have a wpf chart with lot of lengend items,
how can i wrap legend items or  show its in multiple rows?

help me please Embarrassed
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3244
Joined: Oct 19th, 2005
Re: how to wrap legend items or show in multiple rows
Reply #1 - Jun 4th, 2020 at 3:40pm
Print Post  
Hi,

Try this, possibly change x:Type to ChartLegend depending on what legend class you are using -

Code
Select All
<Window.Resources>
    <Style TargetType="{x:Type chart:SeriesLegend}">
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <WrapPanel MaxHeight="80" Orientation="Vertical" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
 



Alternatively, you could add multiple Legend objects to the chart.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
sami
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Jun 4th, 2020
Re: how to wrap legend items or show in multiple rows
Reply #2 - Jun 6th, 2020 at 9:51am
Print Post  
hi dear,
thanks for relpy,
my legend class is SeriesLegend,

but your code not  Work,
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3244
Joined: Oct 19th, 2005
Re: how to wrap legend items or show in multiple rows
Reply #3 - Jun 6th, 2020 at 11:07am
Print Post  
Hi,

That template creates a second column only if you have enough legend items to fill the 80-points MaxHeight. Change the wrap panel's Orientation to Horizontal to immediately arrange in a row instead, and set MaxWidth to specify at what points it should wrap to a second row.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
sami
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Jun 4th, 2020
Re: how to wrap legend items or show in multiple rows
Reply #4 - Jun 8th, 2020 at 11:45am
Print Post  
hi,
ooops,very nice,
this worked,thanks a lot,

excuse me ,i have another question

my chart width properites is not fix,in the other words,the HorizontalAlignment properties of chart set to Stretch,
how to set maxwidth of wrap panel to chart real width??
is there a solution??
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3244
Joined: Oct 19th, 2005
Re: how to wrap legend items or show in multiple rows
Reply #5 - Jun 8th, 2020 at 2:32pm
Print Post  
Hi,

Something like this -

Code
Select All
<WrapPanel
    MaxWidth="{Binding RelativeSource=
        {RelativeSource Mode=FindAncestor,
            AncestorType={x:Type chart:BarChart}},
        Path=Width}"
    Orientation="Horizontal" />
 



and you'll probably want to move legends to top or bottom of the plot, or otherwise they'll clamp the plot if on the sides -
LayoutPanel.SetDock(legend1, Dock.Bottom);

Regards,
Slavcho
  
Back to top
 
IP Logged
 
sami
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Jun 4th, 2020
Re: how to wrap legend items or show in multiple rows
Reply #6 - Jun 22nd, 2020 at 2:22pm
Print Post  
oh my friend,
this is very nice
,its worked

thank you Cheesy Cheesy

but,why only barchart?
you have a method for all type of chart?
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3244
Joined: Oct 19th, 2005
Re: how to wrap legend items or show in multiple rows
Reply #7 - Jun 23rd, 2020 at 6:44am
Print Post  
base chart class should work too if you want this template for more chart types -

Code
Select All
AncestorType={x:Type chart:Chart} 



Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint