我在c#的报告中设置了一个DevExpress xrGraph。系列数据绑定到一个对象,但是每个系列都需要来自一个单独的对象...不能很好地解释但是要说明:
到目前为止我有什么
public class Data {
public List<TestItem> Tests {get; set;}
}
public class TestItem {
public string TestNumber {get; set;}
public Graph GraphData {get; set;}
}
public class Graph {
public List<Tuple<string, decimal, decimal>> Samples {get; set;}
}
然后......
var test1Info = new TestItem();
test1Info.TestNumber = "Test 1";
test1Info.GraphData.Samples = new List<Tuple<string, decimal, decimal>>
{
new Tuple<string, decimal, decimal>("Test 1", 0, 0),
new Tuple<string, decimal, decimal>("Test 1", 0.01M, 0.07M),
new Tuple<string, decimal, decimal>("Test 1", 0.02M, 0.14M),
new Tuple<string, decimal, decimal>("Test 1", 0.03M, 0.20M),
new Tuple<string, decimal, decimal>("Test 1", 0.04M, 0.26M),
new Tuple<string, decimal, decimal>("Test 1", 0.05M, 0.31M)
};
report.TestData.Add(test1Info);
var test2Info = new TestItem();
test2Info.TestNumber = "Test 2";
test2Info.VolumeTimeInfo.Samples = new List<Tuple<string, decimal, decimal>>
{
new Tuple<string, decimal, decimal>("Test 2", 0, 0),
new Tuple<string, decimal, decimal>("Test 2", 0.01M, 0.07M),
new Tuple<string, decimal, decimal>("Test 2", 0.02M, 0.21M),
new Tuple<string, decimal, decimal>("Test 2", 0.03M, 0.55M),
new Tuple<string, decimal, decimal>("Test 2", 0.04M, 0.90M),
new Tuple<string, decimal, decimal>("Test 2", 0.05M, 1.66M),
new Tuple<string, decimal, decimal>("Test 2", 0.06M, 1.99M),
new Tuple<string, decimal, decimal>("Test 2", 0.07M, 2.15M)
}
report.TestData.Add(test2Info);
在我的图表属性中,我设置了
SeriesDataMember
至TestData.Tests.Samples.Item1
和SeriesTemplate
:
ArgumentDataMember
至TestData.Tests.Samples.Item2
在ValueDataMambers
我已将Value
设为TestData.Tests.Samples.Item3
问题:
但是,图表只绘制了一条曲线,即测试1.我怎样才能看到Tests
出现的其余部分?现在,如果我将Test 2数据移动到test1Info(即第一次出现Tests
,那么将显示它们都很好。但是我不想这样做。一方面,这些类很多比上面给出的代码更复杂,并且这样做 - 将所有测试放在一起会违背现有的类结构。但是,我相信在每个样本中都有“测试1”等等。很麻烦(实际上有数千个),我宁愿从TestNumber
属性中取出标签。
但是目前如果我将SeriesDataMember
设置为TestData.Tests.TestNumber
,现在我可以看到Legend中的两个测试,但只有一个点(第一个测试的样本中的第一个点)在图表上绘制!
这样做的正确方法是什么?
答案 0 :(得分:0)
我通过在Data
类中添加一个属性来解决这个问题,该类以dev表达式似乎需要它的格式返回数据。感觉有点像一种解决方法,我不确定它是否更有效,所以我仍然想知道是否有正确的方法来做我想做的事。
首先,我从string
元组中删除了Samples
。然后......
public class Data {
public List<TestItem> Tests {get; set;}
public List<Tuple<string, decimal, decimal>> AllGraphSamples
{
get
{
var allGraphData = new List<Tuple<string, decimal, decimal>>();
foreach (var test in Tests)
{
var graphData = test.GraphData.Samples.Select(
s => new Tuple<string, decimal, decimal>
(
string.Format("Test {0}", test.TestNumber),
s.Item1,
s.Item2
)).ToList();
allGraphData.AddRange(graphData);
}
return allGraphData;
}
}
我的图表现在指向此属性的相同成员而不是GraphData.Samples
。