朝阳区北京网站建设,制作网页教程,网站手机访问跳转,房屋设计软件手机版本文看了博客WPF编程#xff0c;Live Charts使用说明#xff08;2#xff09;——使用_funcchartpoint, string labelpoint-CSDN博客#xff0c;这里作为笔记用。
1.前端代码
前端XAML文件代码如下#xff1a;
Window x:Classlivechart1.MainWindowLive Charts使用说明2——使用_funcchartpoint, string labelpoint-CSDN博客这里作为笔记用。
1.前端代码
前端XAML文件代码如下
Window x:Classlivechart1.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:livechart1xmlns:lvcclr-namespace:LiveCharts.Wpf;assemblyLiveCharts.Wpfmc:IgnorabledTitleMainWindow Height450 Width800GridGrid.RowDefinitionsRowDefinition Height40/RowDefinition//Grid.RowDefinitionsStackPanel OrientationHorizontal VerticalAlignmentCenter Margin10 0 0 0Button Width80 Height30 Margin5 0 0 0 Content折线图 ClickButton_Click/Button Width80 Height30 Margin5 0 0 0 Content直方图 ClickButton_Click_1/Button Width80 Height30 Margin5 0 0 0 Content饼状图 ClickButton_Click_2//StackPanelGrid Grid.Row1Grid.ColumnDefinitionsColumnDefinition/ColumnDefinition/ColumnDefinition//Grid.ColumnDefinitionslvc:CartesianChart Names1 LegendLocationToplvc:CartesianChart.AxisYlvc:Axis Names1y Title分数 MinValue0/lvc:Axis/lvc:CartesianChart.AxisYlvc:CartesianChart.AxisXlvc:Axis Names1x Title区域 /lvc:Axis/lvc:CartesianChart.AxisX/lvc:CartesianChartlvc:CartesianChart Names2 Grid.Column1 LegendLocationToplvc:CartesianChart.AxisXlvc:Axis Names2y Title区域 /lvc:Axis/lvc:CartesianChart.AxisXlvc:CartesianChart.AxisYlvc:Axis Names2x Title分数 MinValue0/lvc:Axis/lvc:CartesianChart.AxisY/lvc:CartesianChartlvc:PieChart Names3 LegendLocationTop Grid.Column2//Grid/Grid
/Window以上代码中Grid上面的代码是自己生成的里面有一行是我们加入的这一行是
xmlns:lvcclr-namespace:LiveCharts.Wpf;assemblyLiveCharts.Wpf
Grid .../Grid之间的所有代码复制到里面就行。
2.后端代码
在cs文件中的代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using LiveCharts;
using LiveCharts.Wpf;
using static System.Net.WebRequestMethods;namespace livechart1
{/// summary/// MainWindow.xaml 的交互逻辑/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();}//1.折线图private void Button_Click(object sender, RoutedEventArgs e){SeriesCollection series new SeriesCollection{new LineSeries{Title 深圳,Values new ChartValuesdouble {4,6,5,2,7}},new LineSeries{Title 广州,Values new ChartValuesdouble { 6, 7, 3, 4 ,6 }}};//x轴string[] Labels new[] { 2011, 2012, 2013, 2014, 2015 };s1.Series series;s1x.Labels Labels;s1y.Separator.Step 1;s1y.LabelFormatter new Funcdouble, string((value) {return value.ToString();});}//2.柱状图private void Button_Click_1(object sender, RoutedEventArgs e){SeriesCollection SeriesCollection new SeriesCollection{new ColumnSeries{Title 深圳,Values new ChartValuesdouble { 10, 50, 39, 50 }},new ColumnSeries{Title 广州,Values new ChartValuesdouble { 11, 56, 42 }}};string[] Labels new[] { 2011, 2012, 2013, 2014, 2015 };s2.Series SeriesCollection;s2x.Labels Labels;s2y.Separator.Step 1;}// 3.饼图private void Button_Click_2(object sender, RoutedEventArgs e){SeriesCollection SeriesCollection new SeriesCollection();SeriesCollection.Add(new PieSeries(){Title 高一(1)班,Values new ChartValuesint() { 30 },DataLabels true,LabelPoint new FuncChartPoint, string((chartPoint) {return string.Format({0}{1} ({2:P}), chartPoint.SeriesView.Title, chartPoint.Y, chartPoint.Participation);})});SeriesCollection.Add(new PieSeries(){Title 高一(2)班,Values new ChartValuesint() { 50 },DataLabels true,LabelPoint new FuncChartPoint, string((chartPoint) {return string.Format({0}{1} ({2:P}), chartPoint.SeriesView.Title, chartPoint.Y, chartPoint.Participation);})});SeriesCollection.Add(new PieSeries(){Title 高一(3)班,Values new ChartValuesint() { 20 },DataLabels true,LabelPoint new FuncChartPoint, string((chartPoint) {return string.Format({0}{1} ({2:P}), chartPoint.SeriesView.Title, chartPoint.Y, chartPoint.Participation);})});s3.Series SeriesCollection;}}
}在以上代码中头文件有LiveCharts这个我们需要进入 工具---NuNet 包管理器---管理解决方案进入后搜索LiveCharts然后点击安装即可。 3.最终效果
最后运行代码运行结果如下