首页 > 其他分享 >WPF livecharts

WPF livecharts

时间:2024-04-19 17:13:37浏览次数:25  
标签:Windows System SeriesCollection new using WPF public livecharts

1.Install livecharts.wpf in nuget

2.usercontrol

//xaml
<UserControl x:Class="WpfApp64.Bar"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp64"
             xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <lvc:CartesianChart Series="{Binding SeriesCollection}" LegendLocation="Left">
            <lvc:CartesianChart.AxisX>
                <lvc:Axis Title="Salesman" Labels="{Binding Labels}"/>
            </lvc:CartesianChart.AxisX>
            <lvc:CartesianChart.AxisY>
                <lvc:Axis Title="Sold Apps" LabelFormatter="{Binding Formatter}"/>
            </lvc:CartesianChart.AxisY>
        </lvc:CartesianChart>
    </Grid>
</UserControl>




//xaml.cs
using LiveCharts;
using LiveCharts.Wpf;
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;

namespace WpfApp64
{
    /// <summary>
    /// Interaction logic for bar.xaml
    /// </summary>
    public partial class Bar : UserControl
    {
        public SeriesCollection SeriesCollection { get; set; }
        public string[] Labels { get; set; }
        public Func<double, string> Formatter { get; set; }
        public Bar()
        {
            InitializeComponent();

            InitData();
        }

        private void InitData()
        {
            Random rnd = new Random();
            int startYear = 2019;

            SeriesCollection = new SeriesCollection();
            for (int i = 0; i < 5; i++)
            {
                SeriesCollection.Add
                    (
                    new ColumnSeries()
                    {
                        Title = (startYear++).ToString(),
                        Values = new ChartValues<double> { rnd.Next(910,1000), rnd.Next(10, 100)
                        , rnd.Next(10,100),rnd.Next(10,100) }
                    });
            }
            //SeriesCollection[1].Values.Add(48d);
            Labels = new[] { "C#", "C++", "C", "Go" };
            Formatter = value => value.ToString("N");
            DataContext = this;
        }
    }
}

3.Invoke the customized usercontrol bar

<Window x:Class="WpfApp64.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp64"
        xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <local:Bar/>
    </Grid>
</Window>

 

 

标签:Windows,System,SeriesCollection,new,using,WPF,public,livecharts
From: https://www.cnblogs.com/Fred1987/p/18146432

相关文章

  • WPF多表头表格实现
    前言多表头表格是一个常见的业务需求,然而WPF中却没有默认实现这个功能,得益于WPF强大的控件模板设计,我们可以通过修改控件模板的方式自己实现它。一、需求分析  下图为一个典型的统计表格,统计1-12月的数据。   此时我们有一个需求,需要将月份按季度划分,以便能够直观地......
  • WPF项目使用日志
    提问WPF项目如何使用日志回答引入nugetlog4net加入配置特性[assembly:ThemeInfo(ResourceDictionaryLocation.None,//wherethemespecificresourcedictionariesarelocated//(usedifaresourceisnotfoundinthepage,//orapplicationresourcedict......
  • WPF/C#:让绘制的图形可以被选中并将信息显示在ListBox中
    实现的效果如果你对此感兴趣,可以接着往下阅读。实现过程绘制矩形比如说我想绘制一个3行4列的表格:privatevoidButton_Click_DrawRect(objectsender,RoutedEventArgse){intRow=3;intCol=4;for(inti=0;i<Row;i++){......
  • 界面组件库DevExpress Office File API(WinForms & WPF)v24.1新功能预览
    本文描述了界面组件库DevExpress的OfficeFileAPI(WinForms&WPF)和受Office启发的控件在v24.1中发布的一些功能,并详细介绍了我们当前的抢先体验预览版本v24.1中的内容。DevExpressWPF拥有120+个控件和库,将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress......
  • 【转载】清空WPF自带样式,以及透明按钮
    原文:https://www.cnblogs.com/Cindys/archive/2012/09/11/2680501.html空样式按钮<Stylex:Key="EmptyButtonStyle"TargetType="Button">           <SetterProperty="Padding"Value="0"/>           <SetterProper......
  • 【转】[C#][WPF] GridControl 列宽控制
    在设置DevExpress里的GridControl自动列宽时,有两个方式:view.BestFitColumn(gridColumn);view.BestFitColumns();但我想要达到这样的效果:1、加载配置,读取列宽2、未配置列宽的列自动列宽发现可以这样组合://如果已配置列宽,自动列宽就是配置的宽度if(gridColumn.Widt......
  • 界面组件Telerik UI for WPF 2024 Q1新版亮点 - 全新DateRangePicker组件
    TelerikUIforWPF拥有超过100个控件来创建美观、高性能的桌面应用程序,同时还能快速构建企业级办公WPF应用程序。UIforWPF支持MVVM、触摸等,创建的应用程序可靠且结构良好,非常容易维护,其直观的API将无缝地集成VisualStudio工具箱中。本文将介绍界面组件TelerikUIforWPF在今......
  • WPF 虚拟化
    1通用部分可以参考 优化控件性能-WPF.NETFramework|MicrosoftLearn主要的设置是<SetterProperty="VirtualizingPanel.IsVirtualizing"Value="True"/><SetterProperty="VirtualizingPanel.VirtualizationMode"Value="Recycling&quo......
  • WPF 使用CommunityToolkit.Mvvm进行快速开发
    一、Net框架情况下:NuGet安装CommunityToolkit.Mvvm使用框架可以简洁快速的编辑代码MvvmFoundationViewModel.cs文件内MvvmFoundationViewModel继承ObservableObject属性上添加[ObservableProperty]属性名称第一个字母不要大写,框架会自动生成大写的字段点击查看代码......
  • WPF随笔收录-DataGrid固定右侧列
    一、前言在项目开发过程中,DataGrid是经常使用到的一个数据展示控件,而通常表格的最后一列是作为操作列存在,比如会有编辑、删除等功能按钮。但WPF的原始DataGrid中,默认只支持固定左侧列,这跟大家习惯性操作列放最后不符,今天就来介绍一种简单的方式实现固定右侧列。(这里的实现方式参......