Visifire圖表

来源:http://www.cnblogs.com/s0611163/archive/2017/06/29/7094729.html
-Advertisement-
Play Games

引用DLL: WPFToolkit WPFVisifire.Charts.dll WPFVisifire.Gauges.dll 1、柱狀圖 代碼: public void BindChart1() { List<string> colorList = new List<string>(); List ...


引用DLL:

WPFToolkit

WPFVisifire.Charts.dll

WPFVisifire.Gauges.dll

1、柱狀圖

代碼:

public void BindChart1()
{
    List<string> colorList = new List<string>();
    List<string> fjList = new List<string>(); ;
    List<double> qyonList = new List<double>();
    List<double> qyoutList = new List<double>();
    int outNum = 0;
    int onNum = 0;
    int totalNum = 0;
    string errMsg = string.Empty;
    bool result = false;

    BackgroundWorker worker = new BackgroundWorker();
    worker.DoWork += (s, e) =>
    {
        result = HI.Get<ICameraService>().GetCameraOnline(out colorList, out fjList, out qyonList, out qyoutList, out outNum, out onNum, out totalNum, out errMsg);
    };
    worker.RunWorkerCompleted += (s, e) =>
    {
        try
        {
            txtOnlineCamera.Text = onNum.ToString();
            txtOutlineCamera.Text = outNum.ToString();
            txtTotalCamera.Text = totalNum.ToString();

            Chart chart = new Chart();

            #region 樣式
            //樣式
            chart.ThemeEnabled = true;
            chart.Theme = "Theme2";
            chart.BorderThickness = new Thickness(0);
            chart.Background = new SolidColorBrush(Colors.Transparent);
            chart.ShadowEnabled = false;
            chart.View3D = false;
            chart.AnimationEnabled = false;

            PlotArea pa = new PlotArea();
            pa.Background = new SolidColorBrush(Colors.Transparent);
            pa.ShadowEnabled = false;
            pa.BorderThickness = new Thickness(0);
            chart.PlotArea = pa;
            #endregion

            //綁定Chart
            chart.Series.Clear();
            chart.Titles.Clear();

            chart.Width = this.chart1Grid.Width - 10;
            chart.Height = this.chart1Grid.Height - 10;

            DataSeries dataSeries = new DataSeries();
            DataPoint datapoint = null;

            #region 顏色
            SolidColorBrush[] brushArr = new SolidColorBrush[8];
            brushArr[0] = new SolidColorBrush(Color.FromRgb(237, 133, 140));
            brushArr[1] = new SolidColorBrush(Color.FromRgb(178, 150, 233));
            brushArr[2] = new SolidColorBrush(Color.FromRgb(16, 227, 230));
            brushArr[3] = new SolidColorBrush(Color.FromRgb(176, 235, 124));
            brushArr[4] = new SolidColorBrush(Color.FromRgb(237, 133, 140));
            brushArr[5] = new SolidColorBrush(Color.FromRgb(178, 150, 233));
            brushArr[6] = new SolidColorBrush(Color.FromRgb(16, 227, 230));
            brushArr[7] = new SolidColorBrush(Color.FromRgb(176, 235, 124));
            #endregion

            #region 數據
            for (int i = 0; i < fjList.Count; i++)
            {
                int colorIndex = i % brushArr.Length;
                datapoint = new DataPoint();
                datapoint.AxisXLabel = fjList[i];
                datapoint.YValue = qyonList[i];
                datapoint.Color = brushArr[colorIndex];
                datapoint.Tag = fjList[i];
                datapoint.LabelEnabled = true;
                datapoint.LabelStyle = LabelStyles.Inside;
                datapoint.LabelFontColor = new SolidColorBrush(Colors.White);
                //datapoint.MouseLeftButtonDown += new MouseButtonEventHandler(datapoint_MouseLeftButtonDown); //DataPoint被點擊執行事件 
                dataSeries.DataPoints.Add(datapoint);
            }
            #endregion

            //綁定當滑鼠放上去顯示的信息     
            chart.Series.Add(dataSeries);

            #region 圖表標題
            //圖表標題
            Title title = new Title();
            title.Text = "攝像頭線上率";
            title.FontColor = new SolidColorBrush(Colors.White);
            chart.Titles.Add(title);
            #endregion

            #region 坐標樣式
            AxisLabels yLabel = new AxisLabels();
            yLabel.FontColor = new SolidColorBrush(Colors.White); //y軸刻度文本信息顏色

            ChartGrid yGrid = new ChartGrid();// 設置y軸的橫向刻度虛線
            yGrid.Enabled = true;
            yGrid.LineColor = new SolidColorBrush(Colors.White);

            Axis yAxis = new Axis();
            yAxis.Enabled = true; //是否顯示Y軸刻度、文本
            yAxis.Grids.Add(yGrid);
            yAxis.AxisMinimum = 0;  //y軸刻度最小值
            yAxis.AxisMaximum = 100;  //y軸刻度最大值
            yAxis.Suffix = "%"; //"給刻度添加尾碼 如%";
            yAxis.Interval = 20;    //設置y軸刻度的增量 -- 即2個刻度值之間的的間隔
            yAxis.IntervalType = IntervalTypes.Number;
            yAxis.AxisLabels = yLabel;
            chart.AxesY.Add(yAxis);

            AxisLabels xLabel = new AxisLabels();
            xLabel.FontColor = new SolidColorBrush(Colors.White); //x軸刻度文本信息顏色

            ChartGrid xGrid = new ChartGrid();//設置x軸的縱向刻度虛線
            xGrid.Enabled = false;

            Axis xAxis = new Axis();
            xAxis.Enabled = true; //是否顯示X軸刻度、文本
            xAxis.AxisLabels = xLabel;
            xAxis.Grids.Add(xGrid);

            chart.AxesX.Add(xAxis);
            #endregion

            this.chart1Grid.Children.Clear();
            this.chart1Grid.Children.Add(chart);
        }
        catch { }
    };
    worker.RunWorkerAsync();

}
View Code

 效果圖:

2、堆積柱狀圖

 代碼:

public void PartolTaskChart()
{
    try
    {
        Chart chart = new Chart();

        #region 樣式
        //樣式
        chart.ThemeEnabled = true;
        chart.Theme = "Theme2";
        chart.Background = new SolidColorBrush(Colors.Transparent);
        chart.BorderThickness = new Thickness(0);
        chart.AnimationEnabled = false;
        chart.View3D = false;

        PlotArea pa = new PlotArea();
        pa.Background = new SolidColorBrush(Colors.Transparent);
        pa.ShadowEnabled = false;
        pa.BorderThickness = new Thickness(0);
        chart.PlotArea = pa;
        #endregion

        #region 顏色
        SolidColorBrush[] brushArr = new SolidColorBrush[8];
        brushArr[0] = new SolidColorBrush(Color.FromRgb(237, 133, 140));
        brushArr[1] = new SolidColorBrush(Color.FromRgb(178, 150, 233));
        brushArr[2] = new SolidColorBrush(Color.FromRgb(16, 227, 230));
        brushArr[3] = new SolidColorBrush(Color.FromRgb(176, 235, 124));
        brushArr[4] = new SolidColorBrush(Color.FromRgb(237, 133, 140));
        brushArr[5] = new SolidColorBrush(Color.FromRgb(178, 150, 233));
        brushArr[6] = new SolidColorBrush(Color.FromRgb(16, 227, 230));
        brushArr[7] = new SolidColorBrush(Color.FromRgb(176, 235, 124));
        #endregion

        #region 數據
        List<Dictionary<string, int>> lsDic = new List<Dictionary<string, int>>();
        BackgroundWorker worker = new BackgroundWorker();
        worker.DoWork += (s, e) =>
        {
            lsDic = HI.Get<SunCreate.CombatPlatform.Contract.IVideoPatrol>().GetTackRecordAnalysis(DateTime.Now.AddYears(-1), DateTime.Now.AddDays(1), "1");
        };
        worker.RunWorkerCompleted += (s, e) =>
        {
            try
            {
                #region 巡查次數
                DataSeries dataSeries = new DataSeries();
                dataSeries.RenderAs = RenderAs.StackedColumn;
                dataSeries.ShowInLegend = false;
                dataSeries.Color = brushArr[0];

                foreach (string key in lsDic[0].Keys)
                {
                    //設置點  
                    int val = lsDic[0][key];
                    DataPoint point = new DataPoint();
                    point.ToolTipText = "巡查次數:" + val;
                    point.YValue = val;
                    point.AxisXLabel = key.Replace("合肥市公安局", string.Empty);
                    point.Tag = key.Replace("合肥市公安局", string.Empty);
                    dataSeries.DataPoints.Add(point);
                }

                chart.Series.Add(dataSeries);
                #endregion

                #region 截圖張數
                dataSeries = new DataSeries();
                dataSeries.RenderAs = RenderAs.StackedColumn;
                dataSeries.ShowInLegend = false;
                dataSeries.Color = brushArr[1];

                foreach (string key in lsDic[1].Keys)
                {
                    //設置點  
                    int val = lsDic[1][key];
                    DataPoint point = new DataPoint();
                    point.ToolTipText = "截圖張數:" + val;
                    point.YValue = val;
                    point.AxisXLabel = key.Replace("合肥市公安局", string.Empty);
                    point.Tag = key.Replace("合肥市公安局", string.Empty);
                    dataSeries.DataPoints.Add(point);
                }

                chart.Series.Add(dataSeries);
                #endregion

                #region 價值圖片
                dataSeries = new DataSeries();
                dataSeries.RenderAs = RenderAs.StackedColumn;
                dataSeries.ShowInLegend = false;
                dataSeries.Color = brushArr[2];

                foreach (string key in lsDic[2].Keys)
                {
                    //設置點
                    int val = lsDic[2][key];
                    DataPoint point = new DataPoint();
                    point.ToolTipText = "價值圖片:" + val;
                    point.YValue = val;
                    point.AxisXLabel = key.Replace("合肥市公安局", string.Empty);
                    point.Tag = key.Replace("合肥市公安局", string.Empty);
                    dataSeries.DataPoints.Add(point);
                }

                chart.Series.Add(dataSeries);
                #endregion

            }
            catch { }
        };
        worker.RunWorkerAsync();
        #endregion

        #region 圖表標題
        //圖表標題
        Title title = new Title();
        title.Text = "巡查執行情況";
        title.FontColor = new SolidColorBrush(Colors.White);
        chart.Titles.Add(title);
        #endregion

        #region 坐標樣式
        AxisLabels yLabel = new AxisLabels();
        yLabel.FontColor = new SolidColorBrush(Colors.White); //y軸刻度文本信息顏色

        ChartGrid yGrid = new ChartGrid();// 設置y軸的橫向刻度虛線
        yGrid.Enabled = true;
        yGrid.LineColor = new SolidColorBrush(Colors.White);

        Axis yAxis = new Axis();
        yAxis.Enabled = true; //是否顯示Y軸刻度、文本
        yAxis.Grids.Add(yGrid);
        yAxis.AxisMinimum = 0;  //y軸刻度最小值
        //yAxis.AxisMaximum = 100;  //y軸刻度最大值
        //yAxis.Suffix = "%"; //"給刻度添加尾碼 如%";
        yAxis.Interval = 20;    //設置y軸刻度的增量 -- 即2個刻度值之間的的間隔
        yAxis.IntervalType = IntervalTypes.Number;
        yAxis.AxisLabels = yLabel;
        chart.AxesY.Add(yAxis);

        AxisLabels xLabel = new AxisLabels();
        xLabel.FontColor = new SolidColorBrush(Colors.White); //x軸刻度文本信息顏色

        ChartGrid xGrid = new ChartGrid();//設置x軸的縱向刻度虛線
        xGrid.Enabled = false;

        Axis xAxis = new Axis();
        xAxis.Enabled = true; //是否顯示X軸刻度、文本
        xAxis.AxisLabels = xLabel;
        xAxis.Grids.Add(xGrid);

        chart.AxesX.Add(xAxis);
        #endregion

        this.gridPartolTaskChart.Children.Clear();
        this.gridPartolTaskChart.Children.Add(chart);
    }
    catch { }
}
View Code

 效果圖:

3、雷達圖

代碼:

public void ShowRadar()
{
    try
    {
        Chart chart = new Chart();

        //樣式
        chart.ThemeEnabled = true;
        chart.Theme = "Theme2";
        chart.Background = new SolidColorBrush(Colors.Transparent);
        chart.BorderThickness = new Thickness(0);

        PlotArea pa = new PlotArea();
        pa.Background = new SolidColorBrush(Colors.Transparent);
        pa.ShadowEnabled = false;
        pa.BorderThickness = new Thickness(0);
        chart.PlotArea = pa;

        #region 顏色
        SolidColorBrush[] brushArr = new SolidColorBrush[8];
        brushArr[0] = new SolidColorBrush(Color.FromArgb(128, 237, 133, 140));
        brushArr[1] = new SolidColorBrush(Color.FromArgb(128, 178, 150, 233));
        brushArr[2] = new SolidColorBrush(Color.FromArgb(128, 16, 227, 230));
        brushArr[3] = new SolidColorBrush(Color.FromArgb(128, 176, 235, 124));
        brushArr[4] = new SolidColorBrush(Color.FromArgb(128, 237, 133, 140));
        brushArr[5] = new SolidColorBrush(Color.FromArgb(128, 178, 150, 233));
        brushArr[6] = new SolidColorBrush(Color.FromArgb(128, 16, 227, 230));
        brushArr[7] = new SolidColorBrush(Color.FromArgb(128, 176, 235, 124));
        #endregion

        #region 數據
        //設置類型為雷達圖  
        DataSeries dataSeries = new DataSeries();
        dataSeries.RenderAs = RenderAs.Radar;
        dataSeries.ShowInLegend = false;
        dataSeries.Color = brushArr[0];

        //設置點  
        DataPoint point = new DataPoint();
        point.YValue = 20;
        point.AxisXLabel = "高新分局";
        point.Tag = "高新分局";
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 50;
        point.AxisXLabel = "包河分局";
        point.Tag = "包河分局";
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 70;
        point.AxisXLabel = "新站分局";
        point.Tag = "新站分局";
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 10;
        point.AxisXLabel = "經開分局";
        point.Tag = "經開分局";
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 50;
        point.AxisXLabel = "蜀山分局";
        point.Tag = "蜀山分局";
        dataSeries.DataPoints.Add(point);

        chart.Series.Add(dataSeries);
        #endregion

        #region 數據
        //設置類型為雷達圖  
        dataSeries = new DataSeries();
        dataSeries.RenderAs = RenderAs.Radar;
        dataSeries.ShowInLegend = false;
        dataSeries.Color = brushArr[1];

        //設置點  
        point = new DataPoint();
        point.YValue = 33;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 57;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 25;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 98;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 70;
        dataSeries.DataPoints.Add(point);

        chart.Series.Add(dataSeries);
        #endregion

        #region 數據
        //設置類型為雷達圖  
        dataSeries = new DataSeries();
        dataSeries.RenderAs = RenderAs.Radar;
        dataSeries.ShowInLegend = false;
        dataSeries.Color = brushArr[2];

        //設置點  
        point = new DataPoint();
        point.YValue = 95;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 88;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 50;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 60;
        dataSeries.DataPoints.Add(point);

        point = new DataPoint();
        point.YValue = 83;
        dataSeries.DataPoints.Add(point);

        chart.Series.Add(dataSeries);
        #endregion

        AxisLabels yLabel = new AxisLabels();
        yLabel.FontColor = new SolidColorBrush(Colors.Transparent); //y軸刻度文本信息顏色

        ChartGrid yGrid = new ChartGrid();// 設置y軸的橫向刻度虛線
        yGrid.Enabled = true;
        yGrid.LineColor = new SolidColorBrush(Colors.White);

        Axis yAxis = new Axis();
        yAxis.Enabled = true; //是否顯示Y軸刻度、文本
        yAxis.Grids.Add(yGrid);
        yAxis.AxisMinimum = 0;  //y軸刻度最小值
        yAxis.AxisMaximum = 100;  //y軸刻度最大值
        //yAxis.Suffix = "%"; //"給刻度添加尾碼 如%";
        yAxis.Interval = 25;    //設置y軸刻度的增量 -- 即2個刻度值之間的的間隔
        yAxis.IntervalType = IntervalTypes.Number;
        yAxis.AxisLabels = yLabel;
        chart.AxesY.Add(yAxis);

        AxisLabels xLabel = new AxisLabels();
        xLabel.FontColor = new SolidColorBrush(Colors.White); //x軸刻度文本信息顏色
        xLabel.Background = new SolidColorBrush(Colors.Transparent);

        ChartGrid xGrid = new ChartGrid();//設置x軸的縱向刻度虛線
        xGrid.Enabled = false;

        Axis xAxis = new Axis();
        xAxis.Enabled = true; //是否顯示X軸刻度、文本
        xAxis.AxisLabels = xLabel;
        xAxis.Grids.Add(xGrid);

        chart.AxesX.Add(xAxis);

        this.radarGrid.Children.Add(chart);
    }
    catch { }
}
View Code

效果圖:

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.安裝此模塊需要先安裝sregex運行庫 apt-get update;apt-get install git make gcc -y #Centos改成yum git clone https://github.com/agentzh/sregex cd sregex make make inst ...
  • 之前在使用nginx和nginx-rtmp-module搭建流媒體伺服器的時候遇到一個很尷尬的問題,就是在把nginx-rtmp-module模塊添加到nginx中去的時候,我最開始採取的做法是先卸載原來的nginx,再下載nginx和nginx-rtmp-module的源碼重新編譯並安裝.重裝完之 ...
  • 在使用這種方法之前試過hdmi線連接,vga介面連接結果都不行。查找原因才知道,筆記本的hdmi和vga都只支持輸出,不支持輸入。 從msdn中的博客中得知該spacedesk(親測不支持xp,win7,8,10均可)http://spacedesk.ph/(官網)可以實現區域網內擴展屏幕。該軟體有 ...
  • 1.今天申請搭建了自己的雲虛擬主機 2.有挺多疑問:它只能使用ftp傳入主頁或者網站網頁內容嗎?沒有後臺代碼之類的怎麼實現程式的功能調用? ...
  • 最近在搞一個人臉識別的功能,使用了微軟的認知服務,一下講一個我遇到的小問題。 首先添加相關相應的NuGet:Microsoft.ProjectOxford.Face 然後構造FaceServiceClient並調用DetectAsync方法識別人臉信息。 構造FaceServiceClient需要一 ...
  • 引言大家好像對分析源碼厭倦了,說實在我也會厭倦,不過不看是無法分析其後面的東西,從易到難是一個必要的過程。今天說下EventBus,前幾天園裡的大神已經把其解刨,我今天就藉著大神的肩膀,分析下在eShop項目中EventBus的實現。最近發覺轉發文章不寫出處的,特此加上鏈接:http://inday... ...
  • 代碼: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; namespace SunCreate.Comba ...
  • 代碼: <Grid> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="3*" /> <ColumnDefinition Width="2*" /> <ColumnDefinition Width="2*"/> <ColumnDefin ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...