我想修改(样式)一个WPF Toolkit Stacked100BarSeries图表来查看和运行这样的东西:
我搜索了很多我如何实现这一点,但似乎太复杂了。我想我应该从代码背后做这个,因为图表中的系列数量可能很多(它应该是动态的)。
它应该是基于时间轴的,并按照这4种颜色分为4种(灰色可以是透明的)。
这是我能想到的:
显然这不是我需要的。它有随机颜色,所有系列都列在右边,而且不是基于时间的。 这里的值来自KeyValuePairs,DependentValuePath是“Value”而IndependentValuePath是“Key”。这就是我实现的更多系列在同一条线上的系列(第一组中的“Key”A系列等)。
这是实验性(丑陋)代码:
Stacked100BarSeries barSeries = new Stacked100BarSeries();
SeriesDefinition s1 = new SeriesDefinition();
SeriesDefinition s2 = new SeriesDefinition();
SeriesDefinition s3 = new SeriesDefinition();
SeriesDefinition s4 = new SeriesDefinition();
SeriesDefinition s5 = new SeriesDefinition();
SeriesDefinition s6 = new SeriesDefinition();
SeriesDefinition s7 = new SeriesDefinition();
SeriesDefinition s8 = new SeriesDefinition();
SeriesDefinition s9 = new SeriesDefinition();
SeriesDefinition s10 = new SeriesDefinition();
SeriesDefinition s11 = new SeriesDefinition();
SeriesDefinition s12 = new SeriesDefinition();
s1.DependentValuePath = "Value";
s1.IndependentValuePath = "Key";
s2.DependentValuePath = "Value";
s2.IndependentValuePath = "Key";
s3.DependentValuePath = "Value";
s3.IndependentValuePath = "Key";
s4.DependentValuePath = "Value";
s4.IndependentValuePath = "Key";
s5.DependentValuePath = "Value";
s5.IndependentValuePath = "Key";
s6.DependentValuePath = "Value";
s6.IndependentValuePath = "Key";
s7.DependentValuePath = "Value";
s7.IndependentValuePath = "Key";
s8.DependentValuePath = "Value";
s8.IndependentValuePath = "Key";
s9.DependentValuePath = "Value";
s9.IndependentValuePath = "Key";
s10.DependentValuePath = "Value";
s10.IndependentValuePath = "Key";
s11.DependentValuePath = "Value";
s11.IndependentValuePath = "Key";
s12.DependentValuePath = "Value";
s12.IndependentValuePath = "Key";
List<KeyValuePair<string, int>> l1 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l2 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l3 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l4 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l5 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l6 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l7 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l8 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l9 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l10 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l11 = new List<KeyValuePair<string, int>>();
List<KeyValuePair<string, int>> l12 = new List<KeyValuePair<string, int>>();
for (int i = 0; i < 4; i++)
{
l1.Add(new KeyValuePair<string, int>("D", i ));
l2.Add(new KeyValuePair<string, int>("D", i ));
l3.Add(new KeyValuePair<string, int>("D", i));
l4.Add(new KeyValuePair<string, int>("D", i ));
l5.Add(new KeyValuePair<string, int>("C", i));
l6.Add(new KeyValuePair<string, int>("C", i));
l7.Add(new KeyValuePair<string, int>("B", i ));
l8.Add(new KeyValuePair<string, int>("B", i));
l9.Add(new KeyValuePair<string, int>("B", i));
l10.Add(new KeyValuePair<string, int>("B", i ));
l11.Add(new KeyValuePair<string, int>("A", i));
l12.Add(new KeyValuePair<string, int>("A", i));
}
s1.ItemsSource = l1;
s2.ItemsSource = l2;
s3.ItemsSource = l3;
s4.ItemsSource = l4;
s5.ItemsSource = l5;
s6.ItemsSource = l6;
s7.ItemsSource = l7;
s8.ItemsSource = l8;
s9.ItemsSource = l9;
s10.ItemsSource = l10;
s11.ItemsSource = l11;
s12.ItemsSource = l12;
barSeries.SeriesDefinitions.Add(s1);
barSeries.SeriesDefinitions.Add(s2);
barSeries.SeriesDefinitions.Add(s3);
barSeries.SeriesDefinitions.Add(s4);
barSeries.SeriesDefinitions.Add(s5);
barSeries.SeriesDefinitions.Add(s6);
barSeries.SeriesDefinitions.Add(s7);
barSeries.SeriesDefinitions.Add(s8);
barSeries.SeriesDefinitions.Add(s9);
barSeries.SeriesDefinitions.Add(s10);
barSeries.SeriesDefinitions.Add(s11);
barSeries.SeriesDefinitions.Add(s12);
chart.Series.Add(barSeries);
在XAML文件中,只有一个名为“chart”的图表标记。