This is a migrated thread and some comments may be shown as answers.

size and color binding in pivot map

1 Answer 64 Views
TreeMap and PivotMap
This is a migrated thread and some comments may be shown as answers.
smartpcr
Top achievements
Rank 1
smartpcr asked on 18 Jan 2012, 04:07 PM
I am using radpivotmap. I'd like to bind size and color with two different measures. However, I am having trouble showing color gradients. below is my sample, please indicate what I am doing wrong. Thanks!

xaml:

<Grid x:Name="LayoutRoot" Background="White">
<telerik:RadPivotMap x:Name="pivotMap"/>
</Grid>

code behind:
public class Piza
{
public string Size { get; set; }
public string Topping { get; set; }
public string Name { get; set; }
public double Price { get; set; }
public int Quantity { get; set; }


public static List<Piza> GetAllPizas()
{
List<Piza> pizas=new List<Piza>();
string[] sizes = {"Large", "Medium", "Small","Extra Large"};
string[] toppings = {"peparoni", "meatball", "mushroom", "green pepper", "cheese", "plain"};
string[] names = {"regular", "veggi lover", "meat lover", "peparoni lover", "pan", "cheese ball"};
Random rand=new Random();
for(int i=0;i<100;i++)
{
string size = sizes[rand.Next(0, sizes.Length)];
string topping = toppings[rand.Next(0, toppings.Length)];
string name = toppings[rand.Next(0, names.Length)];
double price = rand.NextDouble()*100;
int quantity = rand.Next(100, 999);
pizas.Add(new Piza
            {
            Size=size,
Topping=topping,
Name=name,
Price=price,
Quantity=quantity
            });
}
return pizas;
}
}

public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
BindPivotMap();
}


/// <summary>
/// size = price
/// color = quantity
/// groups by size, topping 
/// </summary>
private void BindPivotMap()
{
var pizas = Piza.GetAllPizas();
int min = pizas.Min(p => p.Quantity);
int max = pizas.Max(p => p.Quantity);
Color minColor = Colors.Green;
Color maxColor = Colors.Red;


var colorizer =
new ValueGradientColorizer()
{
RangeMinimum = min,
RangeMaximum = max
};
colorizer.GradientStops = new GradientStopCollection();
colorizer.GradientStops.Add(new GradientStop() { Color = minColor, Offset = 0 });
colorizer.GradientStops.Add(new GradientStop() { Color = maxColor, Offset = 1 });
colorizer.ValuePath = "Quantity";


this.pivotMap.BeginInit();
this.pivotMap.ItemsSource = pizas;
this.pivotMap.ValuePath = "Price";
this.pivotMap.GroupDefinitions.Clear();


GroupDefinition sizeGroup = new GroupDefinition();
sizeGroup.Mappings.Clear();
sizeGroup.Mappings.Add(colorizer);
sizeGroup.Member = "Size";
this.pivotMap.GroupDefinitions.Add(sizeGroup);


GroupDefinition toppingGroup = new GroupDefinition();
toppingGroup.Mappings.Clear();
toppingGroup.Mappings.Add(colorizer);
toppingGroup.Member = "Topping";
this.pivotMap.GroupDefinitions.Add(toppingGroup);


this.pivotMap.EndInit();
}



}

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 23 Jan 2012, 11:36 AM
Hi,

I see that you have changed the value path for your colorizer. Unfortunately currently we support only the default value path for colorizers applied on the groups. This is because each group is a IGrouping instance and we have information only for the value of the whole group. You can set this colorizer on the leaf items of your groups, because they have the information needed for the colorizer. Another option is using RadTreeMap, because each treemap level is represented by an object from the specified ItemsSource.

Hope this information helps!

Kind regards,
Yavor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
TreeMap and PivotMap
Asked by
smartpcr
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or