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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • C#MQTTNET客户端使用说明

    C#MQTTNET客户端使用说明C#MQTTNET客户端使用说明1.如何使用1.我想启动MQTT客户端,我该怎么做?2.我想收到服务器发来消息,我该怎么做?3.我想知道客户端是否连接成功,我该怎么做?3.我想知道怎样重连服务器,我该怎么做?1.如何使用1.我想启动MQTT客户端,我该怎么做?try{IMqttClientclient=newMqttFactory().CreateMqttClient();varbuild=newMqttClientOptionsBuilder()//配

    2022年6月25日
    66
  • js 彻底理解回调函数「建议收藏」

    一、前奏在谈回调函数之前,先看下下面两段代码:不妨猜测一下代码的结果。functionsay(value){alert(value);}alert(say);alert(say(‘hijs.’));如果你测试了,就会发现:只写变量名say返回的将会是say方法本身,以字符串的形式表现出来。而在变量名后加()如say()返回的就会使say方法调用后的结果,这里

    2022年4月4日
    56
  • linux网络配置出现E325,Linux启动vi编辑器提示E325:

    linux网络配置出现E325,Linux启动vi编辑器提示E325:vi编辑器是linux的文本编辑器,在linux系统的运用非常广泛,不少朋友在打开vi编辑器的时候提示e325:attention错误,遇到这种情况该怎么办吗?下面秋天网Qiutian.ZqNF.Com小编就给大家介绍下linux打开vi编辑器时提示e325:attention的解决方法。当打开vi编辑器时出现以下的提示时不要着急e325:attentionfoundaswapfile…

    2022年5月19日
    36
  • flyweight设计模式_适配器模式菜鸟

    flyweight设计模式_适配器模式菜鸟亨元模式动机模式定义实例结构要点总结笔记。动机在软件系统采用纯粹对象方案的问题在于大量细粒度的对象会很快充斥在系统中,从而带来很高的运行时代价—主要指内存需求方面的代价如何在避免大量细粒度对象问题的同时,让外部客户仍然能够透明地使用面向对象地方式来进行操作模式定义运用共享技术有效地支持大量细粒度地对象。实例每一个字符都是一个字体 字体对象Fontclass Font{private: //unique object key string key; //object

    2022年8月9日
    14
  • 04 _ 可扩展架构案例(一):电商平台架构是如何演变的?[通俗易懂]

    04 _ 可扩展架构案例(一):电商平台架构是如何演变的?[通俗易懂]本章,我就针对最近十几年电商平台的架构变化过程,来具体说明下,为了支持业务的快速发展,架构是如何一步步演进的。从2003年淘宝上线开始,国内电商平台经历了高速的发展,在这个过程中,系统遇到了很多的挑战,比如说:如何针对当前的业务现状,选择合适的架构呢?如何在业务发展过程中,升级改造架构,并保证系统的平滑过渡呢?接下来,我会结合自己的工作实践,和你一起探讨架构的演变历程,你可以从中了解到各种架构的优劣点和适用性,然后在实际工作中选择合适的架构。这里,我总结了国内电商平台架构发展的大致过程,你可以结合图片

    2022年6月16日
    33
  • ActiveMQ简介与安装

    1.ActiveMQ简介ActiveMQ是一种开源的,实现了JMS1.1规范的,面向消息(MOM)的中间件,为应用程序提供高效的、可扩展的、稳定的和安全的企业级消息通信。ActiveMQ使用Apa

    2021年12月28日
    42

发表回复

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

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