引用的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);
}
}