gpt4 book ai didi

c# - syncfusion winrt图表

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:42 26 4
gpt4 key购买 nike

我正在尝试在我的新 Win8 C#/XAML 商店应用程序中使用 SyncFusion WinRT Studio 中的饼图,但我不知道如何在图表上设置数据。我的页面上有图表,并尝试了我能找到的所有方法来设置数据以显示内容,但我无法让它工作。示例应用程序没有太大帮助,因为它们的页面中有 0 个代码,我无法弄清楚有什么不同。下面的图表是直接从他们的示例中复制的,但它在我的应用程序中不起作用。有人有在 WinRT 应用程序中使用 SyncFusion 图表的示例吗?

XAML 图表:

      <Grid Margin="30,15,30,30" x:Name="ChartGrid">
<Grid.Resources>
<local:Labelconvertor x:Key="labelconverter"/>
<Style TargetType="Line" x:Key="lineStyle">
<Setter Property="StrokeThickness" Value="0"/>
</Style>
<DataTemplate x:Key="labelTemplate">
<TextBlock Margin="10,0,0,0" Text="{Binding Converter={StaticResource labelconverter}}" FontSize="26" FontFamily="Segoe UI" FontWeight="Light" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Top" Opacity="0.5"></TextBlock>
</DataTemplate>
<DataTemplate x:Key="legend">
<StackPanel Orientation="Horizontal">
<Grid Margin="10,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Rectangle Width="15" Height="15" Fill="{Binding Interior}"></Rectangle>
<TextBlock Margin="10,5,5,0" Grid.Column="1" Text="{Binding Item.Expense}"></TextBlock>
</Grid>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<Grid.DataContext>
<local:PieChartViewModel/>
</Grid.DataContext>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Margin="0,0,0,20">
</StackPanel>
<chart:Chart x:Name="ScatterChart" AreaBorderThickness="0" HorizontalAlignment="Center" Grid.RowSpan="2" Visibility="Visible">
<chart:Chart.Header>
<TextBlock FontSize="20" FontFamily="Segoe UI" Margin="0,20,0,10">Agriculture Expenses Comparison</TextBlock>
</chart:Chart.Header>
<chart:Chart.PrimaryAxis>
<chart:ChartAxis></chart:ChartAxis>
</chart:Chart.PrimaryAxis>
<chart:Chart.SecondaryAxis>
<chart:ChartAxis></chart:ChartAxis>
</chart:Chart.SecondaryAxis>
<chart:Chart.Legend>
<chart:ChartLegend CornerRadius="0" ItemTemplate="{StaticResource legend}" CheckBoxVisibility="Visible" BorderThickness="1">
</chart:ChartLegend>
</chart:Chart.Legend>
<chart:PieSeries ItemsSource="{Binding Expenditure}" XBindingPath="Expense" x:Name="pieSeries" ExplodeAll="{Binding Path=IsChecked,ElementName=chkExplode}" ExplodedRadius="{Binding Path=Value,ElementName=slRadius}" Palette="Metro" Label="Expenditures" YBindingPath="Amount">
<chart:PieSeries.AdornmentsInfo>
<chart:ChartAdornmentInfo AdornmentsPosition="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center" ConnectorLineStyle="{StaticResource lineStyle}" ShowConnectorLine="True" ConnectorHeight="30" ShowLabel="True" LabelTemplate="{StaticResource labelTemplate}" SegmentLabelContent="YValue">
</chart:ChartAdornmentInfo>
</chart:PieSeries.AdornmentsInfo>
</chart:PieSeries>
</chart:Chart>
</Grid>
</StackPanel>
</Grid>

从 LoadState 函数调用的代码隐藏:(我已经尝试了所有这些选项,但没有一个有效...)

  PieChartViewModel pvm = new PieChartViewModel();
this.DefaultViewModel["PieChartViewModel"] = pvm;
this.DefaultViewModel["DataContext"] = pvm;
this.DefaultViewModel["Items"] = pvm;
this.DefaultViewModel["DefaultViewModel"] = pvm;
this.ScatterChart.DataContext = pvm;
this.ChartGrid.DataContext = pvm;

对象定义:

public class PieChartViewModel
{
public PieChartViewModel()
{
this.Expenditure = new List<CompanyExpense>();
Expenditure.Add(new CompanyExpense() { Expense = "Seeds", Amount = 20d });
Expenditure.Add(new CompanyExpense() { Expense = "Fertilizers", Amount = 23d });
Expenditure.Add(new CompanyExpense() { Expense = "Insurance", Amount = 12d });
Expenditure.Add(new CompanyExpense() { Expense = "Labor", Amount = 28d });
Expenditure.Add(new CompanyExpense() { Expense = "Warehousing", Amount = 10d });
Expenditure.Add(new CompanyExpense() { Expense = "Taxes", Amount = 10d });
Expenditure.Add(new CompanyExpense() { Expense = "Truck", Amount = 10d });
}
public IList<CompanyExpense> Expenditure
{
get;
set;
}
}
public class CompanyExpense
{
public string Expense { get; set; }
public double Amount { get; set; }
}

最佳答案

我能够毫无问题地使用相同的数据填充饼图。请在 PieChartDemo 找到 sample

这是解释如何配置饼图的文档:PieChartHelp

以下是为生成PieSeries提供数据的三个API,

  1. ItemsSource - 您可以使用此属性提供数据源。任何 IEnumerable 都可以作为数据源。
  2. XBindingPath - 用于提供类别数据在源对象中的路径。
  3. YBindingPath - 用于提供源对象中数字数据的路径。

关于c# - syncfusion winrt图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13782517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com