WPF Visifire图表控件使用基础

WPF Visifire图表控件使用基础https://www.cnblogs.com/wyuan/archive/2012/07/22/WPF.html引言:  由于项目中需要使用Visifire所以自己就写了一些demo,大家一起共享!基础Visifire图表的展示1.Visifire的创建需要引用的DLL包【WPFToolkit.dll;WPFVisifire.Charts;WPFVisifire.Gauges(这个以后会用到)】2

大家好,又见面了,我是你们的朋友全栈君。

https://www.cnblogs.com/wyuan/archive/2012/07/22/WPF.html

引言:

  由于项目中需要使用Visifire所以自己就写了一些demo,大家一起共享!

基础Visifire图表的展示

1.Visifire的创建需要引用的DLL包【WPFToolkit.dll;WPFVisifire.Charts;WPFVisifire.Gauges(这个以后会用到)】

2.我们开始创建简单的Visifire图表

第一步:前台代码

<Window x:Class="Wpf_Tray.VisifireWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:vc="clr-namespace:Visifire.Charts;assembly=WPFVisifire.Charts" Title="VisifireWindow" Height="378" Width="536" WindowStartupLocation="CenterScreen">
    <Grid Name="LayoutRoot">
      <vc:Chart Name="chart" DockPanel.Dock="Left" Margin="0,40,0,2" />
      <Button Content="showChartData" Height="23" HorizontalAlignment="Left" Margin="24,8,0,0" Name="btn_showChartData" VerticalAlignment="Top" Width="97" Click="btn_showChartData_Click" />
       <Button Content="ExportToPng" Height="23" HorizontalAlignment="Left" Margin="134,8,0,0" Name="btn_ExportToPng" VerticalAlignment="Top" Width="88" Click="btn_ExportToPng_Click" />
        <Button Content="ExportChart" Height="23" HorizontalAlignment="Left" Margin="233,8,0,0" Name="btn_ExportChart" Click="btn_ExportChart_Click" VerticalAlignment="Top" Width="75" />
    </Grid>
</Window>

写完后的一个显示效果,如图;
http://pic002.cnblogs.com/images/2012/368829/2012072216004293.png

第二步:

实现后台绑定数据,上代码:

/// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            DataSet ds = DBSQLHelper.Search("select * from hospitalorg", null, CommandType.Text);
            BindChart(ds.Tables[0]);
        }
      public VisifireWindow()
        {
            InitializeComponent(); 
            BindData();
        }

http://pic002.cnblogs.com/images/2012/368829/2012072216483217.png

这是绑定一列的!

第三步:

如图,有三个按钮,‘showChartData’,‘ExportToPng’

1.showChartData,主要是多列数据绑定,实现效果如图:
http://pic002.cnblogs.com/images/2012/368829/2012072216592860.png

上代码:

#region 可以显示多列,绑定界面Chart

        private void BindMoreColumnChart(DataTable dtChart)
        {
            this.chart.Series.Clear();

            this.chart.AnimationEnabled = true;

            this.chart.View3D = true;

            DataSeries dataSeries = new DataSeries();

            dataSeries.RenderAs = RenderAs.Bar;

            dataSeries.LabelEnabled = true;

            dataSeries.LegendText = "最小值";//图例显示的信息

            dataSeries.LabelText = "#AxisXLabel, #YValue";

            DataPoint datapoint;

            for (int i = 0; i < dtChart.Rows.Count; i++)
            {

                datapoint = new DataPoint();

                datapoint.AxisXLabel = dtChart.Rows[i]["job_id"].ToString();

                datapoint.YValue = Convert.ToDouble(dtChart.Rows[i]["min_lvl"].ToString());

                dataSeries.DataPoints.Add(datapoint);

            }

            this.chart.Series.Add(dataSeries);




            DataSeries dataSeries1 = new DataSeries();

            dataSeries1.RenderAs = RenderAs.Bar;

            dataSeries1.LabelEnabled = true;

            DataPoint datapoint1;

            for (int i = 0; i < dtChart.Rows.Count; i++)
            {

                datapoint1 = new DataPoint();

                datapoint1.AxisXLabel = dtChart.Rows[i]["job_id"].ToString();

                datapoint1.YValue = Convert.ToDouble(dtChart.Rows[i]["max_lvl"].ToString());

                dataSeries1.DataPoints.Add(datapoint1);
            }

            dataSeries1.LegendText = "最大值";

            dataSeries1.LabelText = "#AxisXLabel, #YValue";

            this.chart.Series.Add(dataSeries1);

            this.chart.ShadowEnabled = true;
        }
        #endregion

2.ExportTopng,是将visifire当前实现的图表导成png,上代码:

#region ExportToPng
        /// <summary>
        /// ExportToPng
        /// </summary>
        /// <param name="path"></param>
        /// <param name="surface"></param>
        public void ExportToPng(Uri path,Visifire.Charts.Chart surface)
        {
            if (path == null) return;
            //Save current canvas transform 保存当前画布变换
            Transform transform = surface.LayoutTransform;
            //reset current transform (in case it is scaled or rotated) 重设当前画布(如果缩放或旋转)
            surface.LayoutTransform = null;
            //Create a render bitmap and push the surface to it 创建一个渲染位图和表面
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap(
                (int)surface.Width,
                (int)surface.Height,
                96d, 96d,
                PixelFormats.Pbgra32);
            renderBitmap.Render(surface);
            // Create a file stream for saving image
            using (FileStream outStream = new FileStream(path.LocalPath,FileMode.Create))
            {
                //Use png encoder for our data
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                // push the rendered bitmap to it
                encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
                // save the data to the stream
                encoder.Save(outStream);
            }
            // Restore previously saved layout 恢复以前保存布局
            surface.LayoutTransform = transform;
        }
        #endregion

#region 将Visifire图表保存为图片 http://www.visifire.com/blog/page/15/

        private void btn_ExportToPng_Click(object sender, RoutedEventArgs e)
        {
            ExportToPng(new Uri("D:/Visifire.png"), this.chart);
        }
#endregion

【这只是基础,visifire官方网站的文档进行学习,http//www.visifire.com/】

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162830.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • FAE 之行小结

    FAE 之行小结本人在 FAE 的过程中的一些感悟 在即将转行之际作了一些小结 希望给初入 FAE 的同仁们一些认识 能帮助到大家在该岗位上能得心应手 1 担当的职责 FAE fieldapplica 其主要职责对应销售与客户接触 将客户的需求与本公司的产品所能实现的功能相结合 为客户提供解决解决方案 直到后期的现场调试及问题解决与反馈 在不同的阶段其充当的作用也有所不同

    2025年6月20日
    4
  • 电商后台管理系统项目总结(一)

    电商后台管理系统项目总结(一)项目模块分析:用户管理模块、权限管理模块、商品管理模块、订单管理模块、数据统计模块各模块技术点:用户管理模块登录/退出、状态切换、编辑、分页、分配角色、面包屑导航切换权限管理模块添加角色、分配权限、权限展示、编辑、删除权限、面包屑导航切换商品管理模块添加商品、编辑、分页、添加参数、添加属性、选择分类、添加分类订单管理模块数据渲染、分页数据统计模块echarts图表、数据渲染用户管理模块展示:权限管理模块展示:商品管理模块展示:订单管理模块展示:数据统计模块效果

    2022年5月7日
    308
  • mysql和redis的区别

    mysql和redis的区别1.mysql和redis的数据库类型mysql是关系型数据库,主要用于存放持久化数据,将数据存储在硬盘中,读取速度较慢。redis是NOSQL,即非关系型数据库,也是缓存数据库,即将数据存储在缓存中,缓存的读取速度快,能够大大的提高运行效率,但是保存时间有限2.mysql的运行机制mysql作为持久化存储的关系型数据库,相对薄弱的地方在于每次请求访问数据库时,都存在着I/O操作,如果反复…

    2022年6月14日
    39
  • poetry下载_k8s安装工具

    poetry下载_k8s安装工具介绍Poetry是Python中的依赖管理和打包工具,当然它也可以配置虚拟环境。它允许您声明项目所依赖的库,并为您管理(安装/更新)它们。之前一直使用virtualenvwrapper管理虚拟

    2022年8月7日
    6
  • matlab如何导入txt数据画图形_matlab画复杂函数图像

    matlab如何导入txt数据画图形_matlab画复杂函数图像MATLAB读取txt文件数据绘制图像现有data.txt文件存储由数据采集卡读取到的6000000个数据。下面记录最基础的用MATLAB读取txt文件数据并绘制图像的代码。%关闭所有的Figure窗口closeall;%清除工作空间的所有变量,函数,和MEX文件clearall;%加载数据文件,并命名为AA=load(‘data.txt’);%矩阵A的规模,[行,列][m,n]=size(A);%绘制txt文件第一列的数据figure(1);plo

    2022年9月6日
    7
  • eclipse中svn插件的安装与使用「建议收藏」

    eclipse中svn插件的安装与使用「建议收藏」来源:https://www.cnblogs.com/zdfjf/p/5038155.html转自博客园:http://www.cnblogs.com/duanxz/p/3334660.html一.    eclipse中svn插件的安装InstallSubclipseinEclipse3.X(参考官网http://subclipse.tigris.org/)

    2022年9月25日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号