WPF圆环图

引用的dll: LiveCharts.Wpf.dll   LiveCharts.dll  Arthas.dll

下载地址 :https://download.csdn.net/download/m0_37137902/12560883

界面代码:

  xmlns:Metro="clr-namespace:Arthas.Controls.Metro;assembly=Arthas"
      xmlns:ms="clr-namespace:Mindscape.WpfElements.Charting;assembly=Mindscape.WpfElements"
      xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
  <Grid  >
                        <Grid.RowDefinitions >
                            <RowDefinition Height="52"></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid Grid.Row="0">
                            <TextBlock x:Name="txt_nation" Text="2019民族分布"
                               Foreground="Black"
                               VerticalAlignment="Center"
                               HorizontalAlignment="Left"
                               Margin="20,0,0,0"
                               FontSize="16"
                               />
                        </Grid>
                        <Grid Grid.Row="1" Margin="0,10,0,0">



                            <Frame x:Name="page_NationChart"
                       ScrollViewer.CanContentScroll="True" 
                       NavigationUIVisibility="Hidden" Grid.ColumnSpan="2" Grid.RowSpan="2">
                            </Frame>
                        </Grid>

                        <Line X1="0" Y1="50" X2="800" Y2="50"  StrokeEndLineCap="Round"   StrokeThickness="1">
                            <Line.Stroke>
                                <LinearGradientBrush EndPoint="0,0.5" StartPoint="0,0">
                                    <GradientStop x:Name="line_nation" Color="Gray"/>
                                    <GradientStop Offset="100"/>
                                </LinearGradientBrush>
                            </Line.Stroke>
                        </Line>
                    </Grid>

后台赋值:

  private void Nation()
        {
            try
            {
                //< lvc:PieChart Name = "Chart" Grid.Row = "1"
                //          LegendLocation = "Top" InnerRadius = "100" Margin = "0 15" >

                //                    </ lvc:PieChart >

                string sql = @"select  XBMC , PCMC , LQZY ,NewLYSF ,XY ,KLMC,ZYDM,TDDWMC1,ZYMC,NewXKML,KSH,NewZYCC,MZMC  from  MainTable ;";

                DataTable dtNation = CSQLiteHelper.SelectData(sql);

                SeriesCollection = new SeriesCollection();

                SeriesCollection.Clear();

                Dictionary<string, double> Nation = new Dictionary<string, double>();

                List<string> listNation = dtNation.AsEnumerable().Select(d => d.Field<string>("MZMC").Trim()).Distinct().ToList();

                List<string> listNationAll = dtNation.AsEnumerable().Select(d => d.Field<string>("MZMC").Trim()).ToList();

                for (int i = 0; i < listNation.Count; i++)
                {
                    if (!string.IsNullOrEmpty(listNation[i].Trim()))
                    {
                        int m_ThisNationCount = listNationAll.Count(x => x.Trim().Equals(listNation[i]));

                        SeriesCollection.Add(new PieSeries
                        {
                            Title = listNation[i].Trim(),
                            Values = new ChartValues<ObservableValue> { new ObservableValue(m_ThisNationCount) },
                            DataLabels = true
                        });
                    }
                }

                PieChart m_NationChart = new PieChart();

                m_NationChart.Series = SeriesCollection;
                m_NationChart.LegendLocation = LegendLocation.Top;
                m_NationChart.InnerRadius = 100;
                m_NationChart.Foreground = ThemeBrush;

                page_NationChart.Content = m_NationChart;
            }
            catch (Exception ex)
            {
                AppLog.Write(ex.ToString(), LogMessageType.Error);
            }
        }

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值