我在 sql 中有以下数据需要在堆积柱形图中表示。
姓名 类型 金额
Paul T1 100
John T2 200
John T3 300
名称代表 X 轴,类型代表系列。我面临的问题是具有相同名称的重复 X 轴值。这是我在获得重复名称之前遵循的代码示例,但现在没有意义。
SectionData data = GetSectionData(sectionId);
List<double[]> yValues= new List<double[]>();
if (data != null && data.LineItems.Count() > 0)
{
List<string> xValues = new List<string>();
List<string> typeNames = new List<string>();
int index=0;
foreach (var yval in data.LineItems)
{
xValues.Add(yval.Name);
typeNames.Add(yval.TypeName);
double[] temp = new double[data.LineItems.Count()];
temp.SetValue(yval.Amont, index);
yValues.Add(temp);
index++;
}
foreach (string name in typeNames)
{
StackedColumnChart.Series.Add(
new Series
{
Name = name,
ChartType = SeriesChartType.StackedColumn,
Font= new Font("Segoe UI", 8),
CustomProperties="DrawingStyle=Cylinder",
Legend = "Default"
}
);
}
for (int counter = 0; counter < typeNames.Count; counter++)
{
try
{
StackedColumnChart.Series[counter].Points.DataBindXY(xValues, yValues.Select(i => i[counter]).ToList());
}
catch (Exception ex)
{
//throw ex
}
}
}
任何帮助。