WPF Visifire使用

WPF Visifire使用引言:  由于项目中需要使用Visifire所以自己就写了一些demo,大家一起共享!基础Visifire图表的展示1.Visifire的创建需要引用的DLL包【WPFToolkit.dll;WPFVisifire.Charts;WPFVisifire.Gauges(这个以后会用到)】2.我们开始创建简单的Visifire图表第一步:前台代码

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

由于项目中需要使用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>

写完后的一个显示效果,如图;

WPF Visifire使用

第二步:

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

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

#region 绑定界面上的Chart
        /// <summary>
        /// 绑定界面上的Chart
        /// </summary>
        /// <param name="dt">Chart数据源</param>
        public void BindChart(DataTable dtChart)
        {
            //绑定Chart
            this.chart.Series.Clear();
            this.chart.Titles.Clear();
 
            this.chart.AnimationEnabled = true;
            this.chart.ThemeEnabled = true;
            this.chart.Width = 500;
            this.chart.Height = 300;
 
            //使Chart显示三维                                          
            this.chart.View3D = true;
 
            DataSeries dataSeries = new DataSeries();
            //Chart的实例这是以饼图显示       Bubble    
             
            DataPoint datapoint = null;
 
            for (int i = 0; i < dtChart.Rows.Count; i++)
            {
                datapoint = new DataPoint();
                datapoint.AxisXLabel = dtChart.Rows[i]["hospitalName"].ToString();
                datapoint.YValue = Convert.ToDouble(dtChart.Rows[i]["hospitalId"].ToString());
                datapoint.Tag = dtChart.Rows[i]["hospitalId"].ToString();
                //DataPoint被点击执行事件
                datapoint.MouseLeftButtonDown += new MouseButtonEventHandler(datapoint_MouseLeftButtonDown);
                dataSeries.DataPoints.Add(datapoint);
            }
            //绑定当鼠标放上去显示的信息    
            dataSeries.LabelAngle = -30;
            this.chart.Series.Add(dataSeries);
 
            Title title = new Title();
            title.Text = "某某医院...";
            this.chart.Titles.Add(title);
 
            this.chart.ShadowEnabled = true;
        }
 
        #endregion

        public VisifireWindow()        {            InitializeComponent();             BindData();        }

绑定后的效果,如图:

WPF Visifire使用

这是绑定一列的!

第三步:

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

1.showChartData,主要是多列数据绑定,实现效果如图:

WPF Visifire使用

上代码:

#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/162778.html原文链接:https://javaforall.net

(0)
上一篇 2022年7月21日 上午8:36
下一篇 2022年7月21日 上午8:36


相关推荐

  • java利用 aspose-words Word或Excel 转Pdf(无水印、页数限制)

    java利用 aspose-words Word或Excel 转Pdf(无水印、页数限制)1:首先需要引入相关的jarword转pdf需要引入aspose-words-15.8.0-jdk16.jar下载JAR包Wordhttp://note.youdao.com/noteshare?id=1e73ab1c91abad338271d50a881165c2excel转pdf需要引入aspose-cells-8.5.2.jarExcelhttp://note….

    2022年5月25日
    57
  • 解决tomcat启动时的中文乱码问题「建议收藏」

    我们第一次下载或者打开Tomcat时可能在控制台会出现中文乱码问题解决办法1.打开你安装Tomcat的所在目录,本文以7.0.92为例。2.打开后选择conf目录。3.将里面的logging.properties文件用编辑器打开,本例子是使用“Notepad++”编辑器打开。4.打开后大约在50行左右找到java.util.logging.ConsoleHandler.enco…

    2022年4月6日
    48
  • double转BigDecimal,数变大

    double转BigDecimal,数变大环境 Windows764 位 JDK1 8 0 40 publicstatic String args doubled 1 1 BigDecimalbd newBigDecima d 1 BigDecimalbd BigDecimal valueOf d 2 BigDecimalbd

    2026年3月16日
    2
  • 什么是系统可用性[通俗易懂]

    什么是系统可用性[通俗易懂]在一个阳光明媚的周二下午,我正在公司里面看着即将发布的Java12的新特性,这时候女朋友打来电话。晚上下班后,女朋友回到家里面和我说,发现淘宝无法访问的十几分钟后又可以了。系统可用性系统

    2022年6月30日
    26
  • java jpa是什么_jpa是什么框架?jpa是什么意思?

    java jpa是什么_jpa是什么框架?jpa是什么意思?你了解jpa吗?很多人表示,对于jpa是一个什么框架并不是很了解,那么下面就一起通过下面的文章内容来了解一下jpa吧!jpa其实就是JavaPersistenceAPI的简称,它的中文名字是Java持久层API,是JDK5.0注解或者XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库当中。JPA的总体思想和现有Hibernate、TopLink、JDO等ORM框架大体一致,总…

    2022年6月29日
    34
  • 软件测试基础知识 – 集成测试和系统测试的区别,以及它们的应用场景

    软件测试基础知识 – 集成测试和系统测试的区别,以及它们的应用场景分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.netDefinitionConverttheinterfaceofaclassintoanotherinterfaceclientsexpect.Adapterletsclassesworktogetherthat…

    2022年6月29日
    38

发表回复

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

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