Vb.net在图表中添加第二行 [英] Vb.net add a second line to a chart
本文介绍了Vb.net在图表中添加第二行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从这些数据中绘制两条线
I'm trying to graph two lines from this data
Here is my excel spreadsheet ----
sheet 1
time value1
0 6
1 6
2 7
3 6
4 5
5 6
6 7
7 6
8 5
9 4
10 3
sheet 2------------------------------
time value2
0 5
1 5
2 6
3 5
4 4
5 5
6 6
7 5
8 4
9 3
10 2
什么我试过了:
What I have tried:
Here is the code that generates one graph line from sheet 1
Imports Excel = Microsoft.Office.Interop.Excel
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
xlApp.Visible = True
xlWorkBook = xlApp.Workbooks.Open("L:\x_GGNS_addons\WorkingJunk\book1.xlsx")
xlWorkSheet = CType(xlWorkBook.Sheets("sheet1"), Excel.Worksheet)
Dim xlcharts = xlWorkSheet.ChartObjects
Dim myChart As Excel.ChartObject = xlcharts.Add(180, 80, 300, 250)
Dim chartPage As Excel.Chart = myChart.Chart
chartPage.Activate()
With chartPage
Dim range1 As Excel.Range
Dim range2 As Excel.Range
Dim chartRange As Excel.Range
'range1 = xlWorkSheet.Range("$A$1", "$A$10")
range1 = xlWorkSheet.Range("sheet1!$A$1:$A$10")
'range2 = xlWorkSheet.Range("$B$1", "$B$10")
range2 = xlWorkSheet.Range("sheet1!$B$1:$B$10")
chartRange = xlApp.Union(range1, range2)
.SetSourceData(chartRange, Excel.XlRowCol.xlColumns)
.ApplyCustomType(Excel.XlChartType.xlXYScatterLines)
.Location(Excel.XlChartLocation.xlLocationAsNewSheet, "chart1")
End With
End Sub
End Class
上面的代码生成图表为预期。
这是添加第二行的宏
The code above generates the graph as expected.
Here is the macro that adds the second line
Sub Macro1()
'
' Macro1 Macro
'
'
ActiveChart.ChartArea.Select
ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.FullSeriesCollection(2).XValues = "=Sheet2!$A$2:$A$12"
ActiveChart.FullSeriesCollection(2).Values = "=Sheet2!$B$2:$B$12"
ActiveChart.FullSeriesCollection(2).Name = "=Sheet2!$A$2:$A$12"
ActiveChart.FullSeriesCollection(2).Name = "=Sheet2!$B$1"
End Sub
对于我的生活,我无法弄清楚如何在Visual Basic中添加第二行!
帮助!
Robert
For the life of me I cannot figure out how to add the second line in Visual basic!
HELP!
Robert
推荐答案
A
1,
A
这篇关于Vb.net在图表中添加第二行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文