This question is locked. New answers and comments are not allowed.
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();
}
}
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();
}
}