ich habe in meiner Userform das ChartSpace1 (Diagramm) eingefügt und finde aber nirgends eine Beschreibung dazu wie ich im VB Code das Diagramm auf
1. ein Punktdiagramm mit x von y abhängigkeit
2. meine Datenreihen für das Diagramm hinterlegen kann
Das Diagramm in der Userform bekommt aktuell die Daten aus dem Microsoft Office Spreedsheet Control.
Ich habe schon eine Version im Netz gefunden sowas in der Art macht aber zurecht komme ich damit eben nicht.
'Diagramm Parameter Anfang
Dim c
' This example starts by putting the data into Spreadsheet1. Normally,
' the data would already be loaded, but this code was added for completeness.
Spreadsheet1.ActiveSheet.Cells.Clear
Spreadsheet1.ActiveSheet.Cells(2, 1).Value = "0"
Spreadsheet1.ActiveSheet.Cells(3, 1).Value = "10"
Spreadsheet1.ActiveSheet.Cells(4, 1).Value = "24"
Spreadsheet1.ActiveSheet.Cells(5, 1).Value = "65"
Spreadsheet1.ActiveSheet.Cells(1, 2).Value = "Perot"
Spreadsheet1.ActiveSheet.Cells(2, 2).Value = y1
Spreadsheet1.ActiveSheet.Cells(3, 2).Value = y2
Spreadsheet1.ActiveSheet.Cells(4, 2).Value = y3
Spreadsheet1.ActiveSheet.Cells(5, 2).Value = y4
Spreadsheet1.ActiveSheet.Cells(1, 3).Value = "Clinton"
Spreadsheet1.ActiveSheet.Cells(2, 3).Value = y5
Spreadsheet1.ActiveSheet.Cells(3, 3).Value = y6
Spreadsheet1.ActiveSheet.Cells(4, 3).Value = y7
Spreadsheet1.ActiveSheet.Cells(5, 3).Value = 0.62
Spreadsheet1.ActiveSheet.Cells(1, 4).Value = "Bush"
Spreadsheet1.ActiveSheet.Cells(2, 4).Value = 0.42
Spreadsheet1.ActiveSheet.Cells(3, 4).Value = 0.12
Spreadsheet1.ActiveSheet.Cells(4, 4).Value = 0.55
Spreadsheet1.ActiveSheet.Cells(5, 4).Value = 0.25
' Clear the contents of the chart workspace. This removes
' any old charts that may already exist and leaves the chart workspace
' completely empty. One chart object is then added.
ChartSpace1.Clear
ChartSpace1.Charts.Add
Set c = ChartSpace1.Constants
ChartSpace1.Charts(0).Type = c.chChartTypeLine ' Definition für das Liniendiagramm
' Set the chart DataSource property to the spreadsheet.
' It is possible to specify multiple data sources, but this example uses only one.
ChartSpace1.DataSource = Spreadsheet1
' Add three series to the chart.
ChartSpace1.Charts(0).SeriesCollection.Add
' ChartSpace1.Charts(0).SeriesCollection.Add
' ChartSpace1.Charts(0).SeriesCollection.Add
' Connect the chart to data by specifying spreadsheet cell references
' for the different data dimensions. Notice that the SetData method uses
' a data source index of 0; this is the first data source, which was previously
' set to the spreadsheet. If you had created multiple data sources,
' you could specify the index to any item in the WCDataSources collection for the
' data source index. For example, if two spreadsheet controls were attached to this
' chart workspace, you could set data from the first control using index 0
' and set data from the second control using index 1.
' Notice that the series name is also bound to a spreadsheet cell. Changing
' the contents of the cell "B1" will also change the name that appears in the legend.
' If you don't want this behavior, set SeriesCollection(0).Caption instead of
' using the SetData method to bind the series name to the spreadsheet.
' Series one contains election data for Perot.
' Bind the series name, the category names, and the values.
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimSeriesNames, 0, "B1"
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimCategories, 0, "A2:A5"
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, 0, "B2:B5"
' Series two contains election data for Clinton.
' ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimSeriesNames, 0, "C1"
' ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimCategories, 0, "A2:A5"
' ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimValues, 0, "C2:C5"
' Series two contains election data for Bush.
' ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimSeriesNames, 0, "D1"
' ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimCategories, 0, "A2:A5"
' ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimValues, 0, "D2:D5"
' Make the chart legend visible, format the left value axis as percentage,
' and specify that value gridlines are at 10% intervals.
ChartSpace1.Charts(0).HasLegend = False
' ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "0%"
ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).MajorUnit = 0.1
'Diagramm Parameter Ende