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

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:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=True, Other:=False, FieldInfo:= _
Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7 _
, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array _
(14, 1)), TrailingMinusNumbers:=True

x3 = Application.CountA(Range("B:B"))
For i = 1 To x3
If Range("B" & i).Value > 1000 Then
Range("B" & i).Value = Range("B" & i).Value / 1024 / 1024 / 1024
End If
Next

‘筛选出表1中不重复的值
r = ActiveSheet.Range("A65536").End(xlUp).Row
If r = 1 Then Exit Sub ‘如果第一列没有数据那么退出程序
Set Dic = CreateObject("scripting.dictionary") ‘创建字典对象
For i = 1 To r ‘将第一列数据添加到字典的key值中
Dic(CStr(Cells(i, 1))) = ""
Next
arr = Dic.keys ‘返回字典key的数组
Set Dic = Nothing ‘销毁对象
Str = Join(arr, ",")

‘下移一行并对第A1单元格赋值
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1") = 8

‘将所有的数据类型复制到G列的单元格中
x1 = Application.CountA(arr)
For i = 0 To (x1 - 1)
Sheets("Sheet1").Activate
Selection.AutoFilter
ActiveSheet.Range("$A$1:$C$1000").AutoFilter Field:=1, Criteria1:="*" & arr(i) & "*"
Columns("A:D").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
Selection.AutoFilter
Rows("1:1").Delete Shift:=xlUp
Rows("1:1").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Value = Range("a3").Value
ActiveSheet.Name = "表" & (i + 1)
Next

‘复制时间戳到中转表
Sheets("表1").Activate
Range("C:C").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
ActiveSheet.Name = "中转表"

‘转移筛选好的数据到中转表
For i = 1 To 5
Sheets("表" & i).Select
Range("B:B").Select
Selection.Copy
Sheets("中转表").Activate
x4 = Application.CountA(Rows(3))
Columns(x4 + 1).Select
ActiveSheet.Paste
Next

‘创建内存数据表
Sheets("表1").Activate
Range("C:C").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
ActiveSheet.Name = "内存"
‘创建CPU数据表
Sheets("表1").Activate
Range("C:C").Select
Selection.Copy
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Paste
ActiveSheet.Name = "CPU"

‘注入数据
For i = 1 To x1
Sheets("中转表").Activate
c = Cells(1, (i + 1)) Like "*cpu*"

If c = True Then
Columns(i + 1).Select
Selection.Copy
Sheets("CPU").Activate
x4 = Application.CountA(Rows(3))
Columns(x4 + 1).Select
ActiveSheet.Paste

Else
Columns(i + 1).Select
Selection.Copy
Sheets("内存").Activate
x4 = Application.CountA(Rows(3))
Columns(x4 + 1).Select
ActiveSheet.Paste
End If
Next

‘处理时间戳
Sheets("内存").Select
x4 = Application.CountA(Columns(1))
x4 = x4 + 1
For i = 2 To x4
Range("A" & i) = (Range("A" & i) + 8 * 3600) / 86400 + 70 * 365 + 19
Range("A" & i).NumberFormatLocal = "[$-F400]h:mm:ss AM/PM"
Range("A" & i).Value = Range("A" & i).Text
Next

Sheets("CPU").Select
x4 = Application.CountA(Columns(1))
x4 = x4 + 1
For i = 2 To x4
Range("A" & i) = (Range("A" & i) + 8 * 3600) / 86400 + 70 * 365 + 19
Range("A" & i).NumberFormatLocal = "[$-F400]h:mm:ss AM/PM"
Range("A" & i).Value = Range("A" & i).Text
Next

‘执行画图操作
Sheets("CPU").Select

x2 = Application.CountA(Columns(2))
x3 = Application.CountA(Rows(2))
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range(Range("B2"), Range(Chr(64 + x3) & x2))
x3 = x3 - 1
For i = 1 To x3
ActiveChart.SeriesCollection(i).Name = "=CPU!$" & Chr(65 + i) & "$1"
Next i
ActiveChart.SeriesCollection(1).XValues = "=CPU!$A$2:$A$" & x2
x3 = x3 + 1
For i = 2 To x3
Dim MEMRange As Range
Set MEMRange = Range(Range(Chr(64 + i) & 2), Range(Chr(64 + i) & x2))

‘平均值
Range(Chr(64 + i) & (x2 + 3)).Select
ActiveCell.FormulaR1C1 = "平均值"
Range(Chr(64 + i) & (x2 + 4)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Average(MEMRange)

‘最大值
Range(Chr(64 + i) & (x2 + 5)).Select
ActiveCell.FormulaR1C1 = "最大值"
Range(Chr(64 + i) & (x2 + 6)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Max(MEMRange)

‘最小值
Range(Chr(64 + i) & (x2 + 7)).Select
ActiveCell.FormulaR1C1 = "最小值"
Range(Chr(64 + i) & (x2 + 8)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Min(MEMRange)

Next i

Sheets("内存").Select

x2 = Application.CountA(Columns(2))
x3 = Application.CountA(Rows(2))
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
ActiveChart.SetSourceData Source:=Range(Range("B2"), Range(Chr(64 + x3) & x2))
x3 = x3 - 1
For i = 1 To x3
ActiveChart.SeriesCollection(i).Name = "=内存!$" & Chr(65 + i) & "$1"
Next i
ActiveChart.SeriesCollection(1).XValues = "=内存!$A$2:$A$" & x2
x3 = x3 + 1
For i = 2 To x3

Set MEMRange = Range(Range(Chr(64 + i) & 2), Range(Chr(64 + i) & x2))

‘平均值
Range(Chr(64 + i) & (x2 + 3)).Select
ActiveCell.FormulaR1C1 = "平均值"
Range(Chr(64 + i) & (x2 + 4)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Average(MEMRange)

‘最大值
Range(Chr(64 + i) & (x2 + 5)).Select
ActiveCell.FormulaR1C1 = "最大值"
Range(Chr(64 + i) & (x2 + 6)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Max(MEMRange)

‘最小值
Range(Chr(64 + i) & (x2 + 7)).Select
ActiveCell.FormulaR1C1 = "最小值"
Range(Chr(64 + i) & (x2 + 8)).Select
ActiveCell.FormulaR1C1 = Application.WorksheetFunction.Min(MEMRange)

Next i

End Sub

时间: 2024-10-17 20:22:46

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

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

第一种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

JFreeChart应用(生成折线图)

1.jar包,jcommon.jar和jfreechart.jar,具体用哪个版本官网去down吧: 还有另外一个jar包,gnujaxp.jar,这个引入之后编译的时候会报错,应该是xsd校验的问题,索性直接去掉了,不影响实现. 2.具体实现: public static void main(String [] args){ //数据源 String[] rk = getRowKeys(bid); double[][]data = getData(bid,rk); String[] colKe

python生成折线图

图形生成工具包 reportlab (下载地址:https://bitbucket.org/rptlab/reportlab/get/ddf3d4f5066a.zip) 数据地址:ftp://ftp.swpc.noaa.gov/pub/weekly/Predict.txt #! /usr/bin/env python #coding=utf-8 #sunspots_final.py from urllib import request from reportlab.graphics.shapes

自定义动态生成折线图

package com.example.line; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Canvas; import android.graphi

echarts生成折线图

<div id="main" style="width: 100%;height:400px;"></div> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 使用刚指定的配置项和数据显示图表. $.post('syqgeneral.do').done(function(result) { var arrDate