網(wǎng)站首頁 編程語言 正文
前言
在做項目的時候,遇到一個需求,需要我對Chart圖標標記數(shù)據(jù)正在運行,實現(xiàn)數(shù)據(jù)可視化,因為我們的表格是隱藏Y軸的刻度是看不到數(shù)據(jù)值的,于是采用數(shù)據(jù)標記的形式來動態(tài)展示值,那么我們應(yīng)該怎么去處理這個問題呢,閱讀這篇文章吧,我們一起學習學習一下,創(chuàng)作不易,大家點贊關(guān)注評論收藏,你的點贊和關(guān)注是我創(chuàng)作的動力,也是我持續(xù)不斷學習的動力。謝謝大家啦?。?!
效果展示
先來展示一下我們的效果,看看是怎么回事,在看看有沒有欲望往下面看看文章,主要是對Chart圖的標記問題做了處理,我們使用了Chart控件的一個對Point點的設(shè)置實現(xiàn)這種動態(tài)展示Chart圖的標記,兩張圖的效果對比非常明顯,對于我們 有這樣的需求的項目可以采用這樣的形式,或者采用另一種的鼠標點擊彈出提示,下篇文章應(yīng)該會寫出來和大家一起學習一下,大家多點贊,我創(chuàng)作的動力更強。
解決方法
我們來看一下解決的方法,我使用Chart控件里面對Point的MarkerStyle 進行標記,實現(xiàn)這樣的方式,對MarkerStyle 的樣式設(shè)置標記大小,標記顏色,以及標記展示的值,使用的是隨機函數(shù)產(chǎn)生的數(shù)據(jù),生成的表格,對表格的數(shù)據(jù)添加,然后在對這個點進行標記,只標記最新是使用標一個去一個的方式,就是我把最新的標記好,把上一個去掉標記,哪個按鈕我只給了一個狀態(tài)值讓它去判斷是最新還是一直標記,也可以加個狀態(tài)不標記。后面貼了代碼你們可以后期自己二次更新。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
namespace TestIC00
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
}
public int index = 0;
public bool flag = false;
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = !timer1.Enabled;//對定時器的操作,點擊打開或關(guān)閉定時器,主要是實現(xiàn)一秒傳一個值
}
private void timer1_Tick(object sender, EventArgs e)
{
Random random = new Random();
this.chart1.ChartAreas[0].AxisX.MajorGrid.Interval = 1;//網(wǎng)格間隔
this.chart1.ChartAreas[0].AxisX.MinorGrid.Interval = 1;
this.chart1.ChartAreas[0].AxisY.MajorGrid.Interval = 1;//網(wǎng)格間隔
this.chart1.ChartAreas[0].AxisY.MinorGrid.Interval = 1;
this.chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//設(shè)置X軸的值的間隔大小
this.chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.Gray;//設(shè)置X軸網(wǎng)格線顏色
this.chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.Gray;//設(shè)置Y軸網(wǎng)格線顏色
chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;//啟動滾動條
this.chart1.ChartAreas[0].AxisY.LabelStyle.Enabled = false;//使Y軸的刻度隱藏
chart1.ChartAreas[0].AxisX.ScaleView.Scroll(System.Windows.Forms.DataVisualization.Charting.ScrollType.Last);//啟用視圖實現(xiàn)數(shù)據(jù)滾動
int value = random.Next(0, 20);//產(chǎn)生隨機數(shù)進行賦值
chart1.Series[0].Points.AddY(value);//對折線圖添加數(shù)據(jù)
if(flag)//判斷標記,如果是true表示只標記最新,需要去掉前面的一個值
{
this.chart1.Series[0].Points[index].MarkerStyle = MarkerStyle.Circle;//設(shè)置標記的形狀為圓形
this.chart1.Series[0].Points[index].MarkerColor = Color.Red;//形狀顏色設(shè)置
this.chart1.Series[0].Points[index].MarkerBorderWidth = 3;//形狀大小設(shè)置
this.chart1.Series[0].Points[index].MarkerSize = 10;//設(shè)置我們展示標記的大小
this.chart1.Series[0].Points[index].Label = "功能:" + this.chart1.Series[0].Name + "\r\n" + "值:" + value.ToString();//對標記展示的值
this.chart1.Series[0].Points[index].IsValueShownAsLabel = true;//展示標記
this.chart1.Series[0].Points[index-1].MarkerBorderWidth = 0;//改前一個標記的大小
this.chart1.Series[0].Points[index - 1].MarkerSize = 0;//形狀大小
this.chart1.Series[0].Points[index - 1].Label = "";//展示數(shù)據(jù)
this.chart1.Series[0].Points[index - 1].IsValueShownAsLabel = false;//不展示
}
else//對數(shù)據(jù)一直標記
{
this.chart1.Series[0].Points[index].MarkerStyle = MarkerStyle.Circle;
this.chart1.Series[0].Points[index].MarkerColor = Color.Red;
this.chart1.Series[0].Points[index].MarkerBorderWidth = 3;
this.chart1.Series[0].Points[index].MarkerSize = 10;
this.chart1.Series[0].Points[index].Label = "功能:" + this.chart1.Series[0].Name + "\r\n" + "值:" + value.ToString();
this.chart1.Series[0].Points[index].IsValueShownAsLabel = true;
}
//也可以加一種狀態(tài)是什么也不標記,你們自己對那個狀態(tài)值的處理就可以啦
index++;
}
private void button2_Click(object sender, EventArgs e)//只標記最新按鈕
{
flag = !flag;//對狀態(tài)值的改變,我就使用了兩種狀態(tài),你們可以改
}
}
}
總結(jié)
這篇文章主要是對博主遇到的一個問題的一種簡單的解決辦法,雖然很簡單,但是還是有技術(shù)含量的,C#的問題太多了,而去解決的人太少,我們要懂得分享,而我們發(fā)文章的人太少啦,所以我把我遇到的一些問題的解決辦法發(fā)出來,讓大家指點我一下,我們一起學習一下,當然還有別的方法,別的方法是用鼠標點擊展示
原文鏈接:https://juejin.cn/post/7132818750155259912
相關(guān)推薦
- 2022-03-14 跨域問題Response to preflight request doesn't pass acc
- 2022-08-27 解決react中useState狀態(tài)異步更新的問題_React
- 2021-09-09 Linux下NTP服務(wù)器配置詳細過程_Linux
- 2022-03-24 c++中的bind使用方法_C 語言
- 2022-06-07 nlp自然語言處理基于SVD的降維優(yōu)化學習_python
- 2022-03-15 使用jib-maven-plugin插件打包docker鏡像上傳到私有鏡像庫,為了賬戶安全,需要設(shè)置
- 2022-07-08 python基礎(chǔ)知識之索引與切片詳解_python
- 2022-10-14 VSC下編寫Makefile文件時,在終端運行make clean命令時報錯的解決方法
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細win安裝深度學習環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支