我已经在 c# 的报告中设置了 DevExpress xrGraph。系列数据绑定(bind)到一个对象,但每个系列都需要来自该对象的单独出现...不好解释但可以说明:
到目前为止我有什么
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。如何让它查看 测试
的其余出现?现在,如果我将 Test 2 数据移动到 test1Info(即 Tests
的第一次出现,那么它们都会显示得很好。但是我不想这样做。一方面,类比我上面给出的代码复杂得多,要做到这一点 - 将所有测试放在一起会违反现有的类结构。而且,我相信每个示例中都有“测试 1”等有点麻烦(实际上有数千个),我宁愿从 TestNumber
属性中获取标签。
但目前如果我将 SeriesDataMember
设置为 TestData.Tests.TestNumber
,现在我可以在图例中看到两个测试,但只有一个点(第一个测试样本的第一个点)绘制在图表上!
正确的做法是什么?
最佳答案
我通过向 Data
类添加一个属性来解决这个问题,该类以 dev express 图表似乎需要的格式返回数据。感觉有点变通,我不确定它是否更有效率,所以我仍然想知道是否有正确的方法来做我想做的事情。
首先,我从 Samples
元组中删除了 string
。然后……
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
成员。
关于c# - devexpress样条xrgraph中的多个系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42670176/