【2019】C1FlexChart中BindingX绑定string字段无法正常显示
xam代码:<Grid Margin="0,0,5,18">
<c1:C1FlexChart x:Name="chartDatUpAndDn"BindingX="Country" ChartType="Bar" ItemsSource="{Binding DataContext.Data}">
<c1:C1FlexChart.Series>
<c1:Series SeriesName="Up" Binding="Sales"/>
<c1:Series SeriesName="Dn" Binding="Expenses"/>
</c1:C1FlexChart.Series>
</c1:C1FlexChart>
</Grid>
源代码:
private List<DataItem> _data;
class DataCreator
{
public static List<DataItem> CreateData()
{
var data = new List<DataItem>();
data.Add(new DataItem("P2", 5, 4));
data.Add(new DataItem("P3", 7, 3));
data.Add(new DataItem("P4", 8, 5));
data.Add(new DataItem("P5", 12, 8));
return data;
}
}
public class DataItem
{
public DataItem(String country, int sales, int expenses)
{
Country = country;
Sales = sales;
Expenses = expenses;
}
public String Country { get; set; }
public int Sales { get; set; }
public int Expenses { get; set; }
}
public UCBarChartUpAndDn()
{
InitializeComponent();
this.DataContext = Data;
}
public List<DataItem> Data
{
get
{
if (_data == null)
{
_data = DataCreator.CreateData();
}
return _data;
}
set
{
this.DataContext = value;
}
}
效果:
问题:Country换成int类型可对应显示,换成String后不管设置什么就显示1,2,3,4
和您这边沟通了解问题是由于ItemsSource绑定的DataContext设置的问题,问题已经解决,那这个帖子就结贴了
页:
[1]