I have X amount of graphs where X is always an even number. Every series shows up as two graphs. One line graph and a Xy Scatter plot. The problem is that the graphs are separated, one to the left, one to the right. I want them to overlap so the points from the Scatter plot shows where the lines break. This is what I want:
But this is what I get:
By the way, these are two different graphs. One shows dates, the other weeks. The one with dates work, the week one doesn't.
This is the code concerning the week graph:
With myChart.Chart
.SeriesCollection(i).XValues = actualdateweek
'actualdateweek is an array with week numbers like 21,22 and so on
.SeriesCollection.NewSeries
If LineGraph = True Then
.SeriesCollection(i).Values = actualdata
.SeriesCollection(i).ChartType = xlLine
.SeriesCollection(i).Format.Line.Visible = msoTrue
.SeriesCollection(i).Format.Line.ForeColor.RGB = RGB(ColorR(i - iModifier - 1), ColorG(i - iModifier - 1), ColorB(i - iModifier - 1))
'actualdata is an array with all the data
elseif XyScatterPlot = True Then
.SeriesCollection(i).Values = actualdata
.SeriesCollection(i).ChartType = xlXYScatter
.SeriesCollection(i).MarkerStyle = xlMarkerStyleSquare
.SeriesCollection(i).Format.Fill.Visible = msoTrue
.SeriesCollection(i).Format.Fill.ForeColor.RGB = RGB(ColorR(i - iModifier - 1), ColorG(i - iModifier - 1), ColorB(i - iModifier - 1))
.SeriesCollection(i).MarkerForegroundColorIndex = -4142
End If
.SeriesCollection(i).AxisGroup = 1
Next i
End With
The graphs are added in turns. First a data series (the actualdata array) is added as a line graph. Then the same data series is added but as a scatter plot. Then the data series changes and it all repeats. So it's like
seriescollection(1).XValues = array filled with week numbers
seriescollection(1).Values = Data series 1
seriescollection(1).ChartType = xlLine
seriescollection(2).XValues = array filled with week numbers
seriescollection(2).Values = Data series 1
seriescollection(2).ChartType = xlXYScatter
seriescollection(3).XValues = array filled with week numbers
seriescollection(3).Values = Data series 2
seriescollection(3).ChartType = xlLine
seriescollection(4).XValues = array filled with week numbers
seriescollection(4).Values = Data series 2
seriescollection(4).ChartType = xlXYScatter
This is what the first graph looks like:
Then when the data to the second graph is added:
.SeriesCollection(i).Values = actualdata
Then the second graph is changed into a scatter plot:
.SeriesCollection(i).ChartType = xlXYScatter
Then an axis group is assigned:
.SeriesCollection(i).AxisGroup = 1
Anyone have an idea what is happening?
edit
Ok problem solved I guess...
By removing the X value for the XYScatterPlot it aligned with the Line Graph.
This line:
.SeriesCollection(i).XValues = actualdateweek
Related
It has been hours that I'm struggling with what I think to be a sible problem since Im not familiar at all with Chart object in VBA.
Here's my chart:
What I want to do: Change the data range of the two axis, the problem is that cant figure out a way to edit the series of the chart.
Thanks four your help !
You could use
With Workbooks(bookname).Charts(Chartname)
.SeriesCollection.NewSeries
.SeriesCollection(i).XValues = YourXs
.SeriesCollection(i).values = YourYs
end with
You can choose which series you want to edit by using the index i. This actually sets the (X,Y) pairings while what's below only changes the range shown by the graph.
To change the bounds of your Y axis you can use
.Axes(xlValue).MinimumScale =
.Axes(xlValue).MaximumScale =
To change the bounds of your x axis use
.Axes(xlCategory).MinimumScale =
.Axes(xlCategory).MaximumScale =
You said you wanted to change
=SERIES("SO2 U5",'CEMS_U6_YTD 2018'!$B$2165:$B$2303,'CEMS_U5_YTD 2018'!$D$2165:$D$2312,1)
to this
=SERIES("SO2 U5",'CEMS_U6_YTD 2018'!$C$2165:$C$2303,'CEMS_U5_YTD 2018'!$D$2165:$D$2312,1)
This may be a simple as
ActiveChart.SeriesCollection(1).Formula = _
"=SERIES(""SO2 U5"",'CEMS_U6_YTD 2018'!$C$2165:$C$2303,'CEMS_U5_YTD 2018'!$D$2165:$D$2312,1)"
note doubling of the double quotes around the series name.
However, since you are only changing the X values, you could use this:
ActiveChart.SeriesCollection(1).XValues = "='CEMS_U6_YTD 2018'!$C$2165:$C$2303"
or
ActiveChart.SeriesCollection(1).XValues = Worksheets("CEMS_U6_YTD 2018").Range("$C$2165:$C$2303")
I've written a tutorial about editing series formulas with VBA: Change Series Formula – Improved Routines.
I managed to create a chart in an Excel worksheet with the following code:
let chartobjects = chartSheet.ChartObjects() :?> ChartObjects
let chartobject = chartobjects.Add(400.0, 20.0, 550.0, 350.0)
chartobject.Chart.ChartWizard(Title = "P&L and Benchmark",
Source = chartSheet.Range("A1", "C" + (string (slen))),
Gallery = XlChartType.xlLine, PlotBy = XlRowCol.xlColumns,
SeriesLabels = 1, CategoryLabels = 1,
CategoryTitle = "", ValueTitle = "NAV")
chartobject.Chart.ChartStyle <- 5
The series plotted have many data points (about 6,000) and fluctuate (stock price data). For this reason the chart lines appear very thick. I would like to make them thinner. This can be done interactively in Excel. Is there a way to do this from F#?
Hi I try to change the color of my excel bar chart via MATLAB.
wksheet = eWorkbook.Worksheets.Item('Sheet2');
co = wksheet.ChartObjects.Item(1); % select the plot (this selects the first plot)
nbSeries = co.Chart.SeriesCollection.count;
% Delete previous series
for i= 1:nbSeries
Series = invoke(co.Chart,'SeriesCollection',1);
invoke(Series,'Delete');
end
% Create Series
nbNewSeries = size(organizedData.Page2.CorrToIndex2Txlsx,1);
for ii = 1:nbNewSeries
NewSeries = invoke(co.Chart.SeriesCollection,'NewSeries');
NewSeries.XValues = organizedData.Page2.CorrToIndex2Txlsx(ii,2);
NewSeries.Values = organizedData.Page2.CorrToIndex2Txlsx(ii,3);
NewSeries.Name = organizedData.Page2.CorrToIndex2Txlsx{ii,1};
end
I have tried this:
NewSeries3.MarkerBackgroundColor = paletteColors(iii,:)*255;
but I get an error:
Parameter must be scalar.
Do you know how can I change colors from MATLAB?
I have this code that allows users to enter chart parameters into some cells and dynamically create a chart. Many series (up to four) are allowed on two vertical (y) axis and one shared horizontal (x) axis. The chart is a mixture of columns and lines normally, and the data ranges are of varying length. I have this code that adds the series like so (I'll try to stick to what I believe is the relevant code)
seriesCount = 1
If hasSeries1 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(2, 6) & " " & axisside1
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType1
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup1
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle1
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor1
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth1
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor1
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine1
ActiveChart.SeriesCollection(seriesCount).XValues = dates1
ActiveChart.SeriesCollection(seriesCount).Values = dataset1
seriesCount = seriesCount + 1
End If
If hasSeries2 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(3, 6) & " " & axisside2
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType2
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup2
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle2
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor2
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth2
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor2
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine2
ActiveChart.SeriesCollection(seriesCount).XValues = dates2
ActiveChart.SeriesCollection(seriesCount).Values = dataset2
seriesCount = seriesCount + 1
End If
If hasSeries3 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(4, 6) & " " & axisside3
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType3
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup3
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle3
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor3
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth3
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor3
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine3
ActiveChart.SeriesCollection(seriesCount).XValues = dates3
ActiveChart.SeriesCollection(seriesCount).Values = dataset3
seriesCount = seriesCount + 1
End If
If hasSeries4 = True Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(seriesCount).Name = .Cells(5, 6) & " " & axisside4
ActiveChart.SeriesCollection(seriesCount).ChartType = chartType4
ActiveChart.SeriesCollection(seriesCount).AxisGroup = axisgroup4
ActiveChart.SeriesCollection(seriesCount).Border.LineStyle = borderStyle4
ActiveChart.SeriesCollection(seriesCount).Border.Color = lineColor4
ActiveChart.SeriesCollection(seriesCount).Format.Line.Weight = lineWidth4
ActiveChart.SeriesCollection(seriesCount).Format.Fill.ForeColor.RGB = seriesColor4
ActiveChart.SeriesCollection(seriesCount).Format.Line.Visible = hasLine4
ActiveChart.SeriesCollection(seriesCount).XValues = dates4
ActiveChart.SeriesCollection(seriesCount).Values = dataset4
End If
Here is the problem: the chart only displays part of the data it is supposed to. When I right-click on the data series, hit Select Data and choose Edit, the correct series (both x and y) become highlighted, but what is being shown is a truncated subset of what should be there.
Here is a sample of what I'm seeing
Here is some of the data for the light blue column
12/30/2005 307%
1/31/2006 302%
2/28/2006 248%
3/31/2006 262%
4/28/2006 285%
5/31/2006 256%
... ...
... ...
... ...
6/30/2014 147%
Notice how this data should be showing on the chart beginning at 12/30/2005, but it's starting at 11/30/2013 instead (though the values appear to be correct, 307%, 302%, etc.). It is almost as though excel is forcing the 2nd and 3rd data series to be the same length as the first one. The first one is charting correctly.
I think you're not using a XY chart, thus you must have the same labels (Xvalues = dates for you) for every series. That means that you need to create a unique dates-set containing all the dates and assign it (as Xvalues) to the first serie.
I've created a VBA for Excel 2007 program that automatically creates bar graphs for ROI based on up to 52 different tabs in the active workbook. I'm close to done, and the only thing I cannot figure out is how to change the colors of the bargraphs.
The graphs are created in their own subfunction, called with a call like so. Every variable changes around whenever it's called.
Call AddChartObject(1, 1, "Example", extraWeeks, weekDifference)
My sub that it calls looks like this.
Sub AddChartObject(j As Integer, k As Integer, passedChartTitle As String, xtraWks As Integer, ttlWks As Integer)
Dim topOfChart As Integer
topOfChart = 25 + (350 * j)
'Adds bar chart for total sales
With ActiveSheet.ChartObjects.Add(Left:=375, Width:=475, Top:=topOfChart, Height:=325)
.Chart.SetSourceData Source:=Sheets("Consolidation").Range("$A$" & 3 + ((17 + xtraWks) _
* j) & ":$C$" & (4 + ttlWks) + ((17 + xtraWks) * k))
.Chart.ChartType = xl3DColumnClustered
.Chart.SetElement (msoElementDataLabelShow)
.Chart.HasTitle = True
.Chart.ChartTitle.Text = passedChartTitle & " Sales"
.Chart.SetElement (msoElementLegendBottom)
.Chart.SetElement (msoElementDataLabelNone)
.Chart.RightAngleAxes = True
End With
End Sub
The RGB color I want to use on the SECOND series in the bar chart is (155, 187, 89), per marketing's wishes. I'm pretty sure there is a .chart.????.???? = RGB (155, 187, 89) command I can use in my With to set this, but I have spent far too much time trying to figure it out, only to come up with nothing.
Have you tried
.Chart.SeriesCollection([index]).Interior.Color = RGB(155, 187, 89)
(where [index] is a placeholder for the series you want to change the color for)?
It works for me ScottyStyles in a very similar situation, but only for the first series collection. I used the same right below that, and that was not changing the color of the SeriesCollection(2). That one is a linear set of datas.
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ClearToMatchStyle
ActiveChart.SeriesCollection(1).Interior.Color = RGB(85, 142, 213)
ActiveChart.SeriesCollection(2).Interior.Color = RGB(192, 0, 0)
to change different bars inside a collection you can use:
ActiveChart.SeriesCollection(1).Points(1).Format.Fill.ForeColor.RGB = RGB(85, 142, 213)
ActiveChart.SeriesCollection(1).Points(2).Format.Fill.ForeColor.RGB = RGB(192,0, 0)
...