第一种vba自动筛选数据自动生成折线图的脚本(自动化)

Sub 数据整理()
Dim iAreaCount As Integer
Dim i As Integer
Dim sTemp, sTemp2 As String
Dim iTemp As Long
Dim bFind As Boolean

Dim ValueName() As String
Dim ValueValue() As Double
Dim ValueDate() As Date

Dim iHour, iMinute, iSecond As Integer
Dim iIndex As Integer

Worksheets("Sheet1").Activate
Range("A1").CurrentRegion.Select
iAreaCount = Selection.Rows.Count

ReDim ValueName(iAreaCount)
ReDim ValueValue(iAreaCount)
ReDim ValueDate(iAreaCount)

Sheets.Add After:=Sheets("Sheet1")
ActiveSheet.Name = "CPU"

Sheets.Add After:=Sheets("Sheet1")
ActiveSheet.Name = "MEM"

For i = 1 To iAreaCount
ValueName(i) = Worksheets("Sheet1").Cells(i, 1).Value
ValueValue(i) = Worksheets("Sheet1").Cells(i, 2).Value
If ValueName(i) Like "*cpu*" Then ValueValue(i) = ValueValue(i) / 100
If ValueName(i) Like "*mem*" Then ValueValue(i) = ValueValue(i) / 1073741824
iTemp = Worksheets("Sheet1").Cells(i, 3).Value
iHour = Int((iTemp Mod 86400) / 3600)
iMinute = Int((iTemp Mod 3600) / 60)
iSecond = Int(iTemp Mod 60)
sTemp = Str(iHour) & ":" & Str(iMinute) & ":" & Str(iSecond)
ValueDate(i) = sTemp

Next i

For i = 1 To iAreaCount
bFind = False
Dim sName As String
sName = Right(ValueName(i), 30)
For Each sht In Sheets
If sName = sht.Name Then bFind = True
Next sht

If bFind Then
Worksheets(sName).Activate
Range("A1").Select
Range("A1").CurrentRegion.Select
iTemp = Selection.Rows.Count + 1
sTemp2 = Mid(Str(iTemp), 2)

sTemp = "A" & sTemp2
Range(sTemp).Select
ActiveCell.FormulaR1C1 = ValueName(i)

sTemp = "B" & sTemp2
Range(sTemp).Select
ActiveCell.FormulaR1C1 = ValueValue(i)

sTemp = "C" & sTemp2
Range(sTemp).Select
ActiveCell.FormulaR1C1 = ValueDate(i)

Else
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = sName
Range("A1").Select
ActiveCell.FormulaR1C1 = ValueName(i)
Range("B1").Select
ActiveCell.FormulaR1C1 = ValueValue(i)
Range("C1").Select
ActiveCell.FormulaR1C1 = ValueDate(i)
End If

Next i

Dim rng1, rng2 As Range

‘cpu chart
Dim ChtCPU As Chart

Worksheets("CPU").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "CPU占用"

Dim iChartIndex As Integer
iChartIndex = 1

For Each sht In Sheets
If sht.Name Like "*cpu*" Then
Worksheets(sht.Name).Activate
Range("A1").Select
Range("A1").CurrentRegion.Select
iTemp = Selection.Rows.Count
sTemp2 = Mid(Str(iTemp), 2)
sTemp = Worksheets(sht.Name).Cells(1, 1).Value

Set rng1 = Sheets(sht.Name).Range("B1", "B" & sTemp2)
Set rng2 = Sheets(sht.Name).Range("C1", "C" & sTemp2)
rng1.NumberFormat = "0.0%"
Worksheets("CPU").Activate
Set ChtCPU = ActiveSheet.ChartObjects(1).Chart
ChtCPU.SeriesCollection.NewSeries
ChtCPU.SeriesCollection(iChartIndex).Values = rng1
ChtCPU.SeriesCollection(iChartIndex).XValues = rng2
ChtCPU.SeriesCollection(iChartIndex).Name = sTemp

iChartIndex = iChartIndex + 1

End If

Next sht

‘memory chart

Dim ChtMEM As Chart

Worksheets("MEM").Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = "内存占用(G)"

iChartIndex = 1

For Each sht In Sheets
If sht.Name Like "*mem*" Then
Worksheets(sht.Name).Activate
Range("A1").Select
Range("A1").CurrentRegion.Select
iTemp = Selection.Rows.Count
sTemp2 = Mid(Str(iTemp), 2)
sTemp = Worksheets(sht.Name).Cells(1, 1).Value
Set rng1 = Sheets(sht.Name).Range("B1", "B" & sTemp2)
rng1.NumberFormat = "0.00"
Set rng2 = Sheets(sht.Name).Range("C1", "C" & sTemp2)

Worksheets("MEM").Activate
Set ChtMEM = ActiveSheet.ChartObjects(1).Chart
ChtMEM.SeriesCollection.NewSeries
ChtMEM.SeriesCollection(iChartIndex).Values = rng1
ChtMEM.SeriesCollection(iChartIndex).XValues = rng2
ChtMEM.SeriesCollection(iChartIndex).Name = sTemp

iChartIndex = iChartIndex + 1

End If

Next sht

End Sub

时间: 2024-11-20 14:55:10

第一种vba自动筛选数据自动生成折线图的脚本(自动化)的相关文章

chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法[bubuko.com]

chart.js插件生成折线图时数据普遍较大时Y轴数据不从0开始的解决办法,原文: 默认情况下如下图 Y轴并不是从0开始,这样折现图的幅度会很大,不是正常的幅度,解决办法如下, 示例代码: window.onload = function () { var ctx = document.getElementById("canvas").getContext("2d"); window.myLine = new Chart(ctx).Line(lineChartDat

highcharts实例教程一:结合php与mysql生成折线图

Highcharts是一款纯javascript和html5编写的图表库,不仅几乎能兼容所有pc浏览器,而且对ios和android手机端的兼容 性也不错,它能够很简单便捷的在Web网站或Web应用中添加交互性的图表,Highcharts目前支持直线图.折线图.面积图.柱状图.饼图.散点图 等多达28种不同类型的图表,还支持3D立体图表的生成,可以满足你对Web图表的任何需求 !而且Highcharts对学习者.非商业机构是免费使用的. 案例场景:要求针对技术cto网站,直观地显示一周网站pv.

使用Highcharts生成折线图_at last

//数据库数据的读取,读取数据后数据格式的转换,还有highchart数据源的配置,伤透了脑筋. anyway,最终开张了.哈哈! 数据库连接:conn_orcale.php <?php $dbconn=oci_connect("dnc-local","dnc-local","orcl")or die("数据库连接错误"); ?> 读取数据:device_query.php <?php require 'co

快速生成折线图及代码详解

快速生成折线图时,只需要修改代码中的以下数据: 1.Y轴刻度个数:Ycounts 2.Y轴最小刻度数:YminValue 3.横坐标:数组mouth 4.标题:strTopic 5.用户数据:数组d 6.[可选]修改背景色:代码中27行改为所需要的颜色即可 完整代码: 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using Sys

MySQL数据表生成ER图

遇到没有说明文档的数据库的时候,一张一张表去分析,需要花费很长时间和精力. 幸好有一些工具,可以帮助我们生成ER图,这样看起来就一目了然: 下面我将自己的一次实践记录于下,供参考: 1.下载并安装工具: 通过官网下载并安装mysql workbench. 下载地址:https://www.mysql.com/products/workbench/    下载完成直接安装就好了. 对于windows平台,可能会需要安装两个组件(Microsoft .NET Framework 4 Client P

第四篇:R语言数据可视化之折线图、堆积图、堆积面积图

前言 折线图通常用来对两个连续变量的依存关系进行可视化,其中横轴很多时候是时间轴. 但横轴也不一定是连续型变量,可以是有序的离散型变量. 绘制基本折线图 本例选用如下测试数据集: 绘制方法是首先调用ggplot函数选定数据集,并在aes参数中指明横轴纵轴.然后调用条形图函数geom_line()便可绘制出基本折线图.R语言示例代码如下: # 基函数 ggplot(BOD, aes(x = Time, y = demand)) + # 折线图函数 geom_line()     运行结果: 向折线

后台获取数据实现实时折线图

折线图用的是echarts的折线图.框架用的ssm,连接oracle数据库,将数据实时显示在折线图上. <div id="main" style="width: 95%; height: 60%; margin: auto;"></div> <script> function showEcharts() { require( [ 'echarts', 'echarts/chart/line' ], function(ec) { /

Python 数据可是化 折线图、散点图、柱状图

总结一些自己在实验中用到的可视化代码,以便于自己以后实验使用. 1.折线图 # %% import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties #mac支持中文 font = FontProperties(fname='/Library/Fonts/Songti.ttc') # 数据准备 x = range(1, 11) y1 = [0.514820119, 0.540265696, 0.

第二种自动整理数据生成折线图(相同的功能,差别却这么大)

Sub 总模块() Dim Dic, arr Dim i As Integer, r As Integer, x1, x2, x3, x4, x5, x6 As Integer Dim Str, Str1 As String '拆分字符串,并针对内存数据进行处理 ActiveSheet.Select Columns("A:A").Select Selection.TextToColumns Destination:=Range("A1"), DataType:=xl