How to change axis value labels orientation? - excel

I have a chart in Excel; I need to change orientation of text labels in one of the axis programmatically. Ideas?

This will change the orientation of the X-axis tick labels.
ActiveChart.Axes(xlCategory).TickLabels.Orientation = 45 ' degrees
This is how to change the orientation of the axis title:
ActiveChart.Axes(xlCategory).AxisTitle.Orientation = 81 ' degrees
Have you ever tried recording macros? If not, you should! Looking at the resulting code is a great way to quickly learn this type of thing.

Layout tab (which appears when you have a chart selected) -> labels -> axis titles.
or
Right click the chart axis -> format axis -> Alignment
or
VBA solution as Jean-François Corbett pointed out

Related

Plotly modify hovermode data

I have a data frame with columns ['run_id','timestamp','pass','fail','no_run'].
I am generating a stacked bar from it.
which looks like
Currently I am generating this stacked bar with x axis as timestamp and y axis as pass/fail/no_run.
The figure layout has hovermode as 'x'.
I would like a way to modify this graph so that when I hover on a bar, instead of showing timestamp in x axis, it should show 'run_id'.
I don't want to change the x axis to run_id while generating the bar chart, it has to be timestamp, but I need a way to modify this hover data.

How to get a scatter Chart Series MarkerBackgroundColor if marker filling is set to Automatic?

I have a scatter chart with multiple series and a trendline per series. I want to set the trendline datalable to be the same color as the series' fill color. The series' fill color is Automatic. The .MarkerBackgroundColor property returns -1 for all series while the .MarkerBackgroundColorIndex returns 2 for all series. I believe this only happens if the marker fill is set to Automatic. However, I can't change that because the series in the chart get added through another VBA code based on dynamic data. Any help?
For i = 1 To Sheet1.ChartObjects("Chart 5").Chart.SeriesCollection.Count
With Sheet1.ChartObjects("Chart 5").Chart.FullSeriesCollection(i)
.Trendlines(1).DataLabel.Format.Fill.ForeColor.RGB = .MarkerBackgroundColor
End With
Next i
In an XY Scatter chart with the marker fill set to "automatic", Excel will apply the colors in the same order as the six theme accent colors in the current palette.
If the chart has more than six series, a lighter/darker shade of these accent colors will be applied, again in the same order. How much lighter/darker actually varies with the Excel version. The screenshot shows the legend for the first 12 series and the default "Office" palette for Office 365 for your reference.
So, if you know the order in which the series sits in the chart, you can surmise its fill color.
Thanks teylyn.
Actually, I made a quick workaround by utilizing the .Trendlines(1).Format.Line.ForeColor.RGB instead of the .MarkerBackgroundColor and it surprisingly works although the Trendline color is set to Automatic as well!
Here is the edited code:
For i = 1 To Sheet1.ChartObjects("Chart 5").Chart.SeriesCollection.Count
With Sheet1.ChartObjects("Chart 5").Chart.FullSeriesCollection(i)
.Trendlines(1).DataLabel.Format.Fill.ForeColor.RGB = .Trendlines(1).Format.Line.ForeColor.RGB
End With
Next i

Excel Charts Hexadecimal axis values

I have Hexadecimal values exported as decimal in an excel sheet (to support chart plotting).
Now, when i plot those values , in the chart's axis i get decimal values. Instead i want hexadecimal values to be shown as axis values..
How can i format the axis to show Hexadecimal values ?
Turn off the vertical axis labels and use data labels to make your own (step-by-step below):
Step 1. Select the bar chart data and create a new bar chart. Format the color.
Step 2. Select the horizontal axis. Under Format Axis > AXIS OPTIONS > Axis Type, select "Text axis".
Step 3. Select the vertical axis. Under Format Axis > LABELS > Label Position, select "None".
Step 4. Right-click the chart. Select "Select Data", then add a new series. Select the series values. Click "OK".
Step 5. Right-click the newly added series. Select "Change Series Chart Type".
Change the newly added series to "Scatter with Straight Lines" and check the "Secondary Axis" checkbox. Click "OK" and change the series color.
Step 6. Add a column of data that starts at 0.5 and increments by 1. Set these as the Series X values for the blue line. Add another three columns of data as shown below.
Step 7. Add a new series to the chart. Select the "x-Axis X" data for the Series X values and the "x-Axis Y" data for the Series Y values and click "OK" twice. Turn on the secondary horizontal axis.
Step 8. Select the newly created series, and add data labels to the left.
Step 9. Right-click the data labels and select "Format Data Labels". Under "LABEL OPTIONS. "Check Value From Cells" and select the x-Axis Labels data. Click "OK" then uncheck "Y Value" and "Show Leader Lines" back in "LABEL OPTIONS".
Step 10. Clean up. Select the x-Axis series and turn off the line and markers. Set the secondary horizontal and vertical axis labels to "None" (Format Axis > AXIS OPTIONS > LABELS).

Match order color and legend in stacked chart with negative values excel

[Problem]
In a very simple stacked bar graph in excel (example data below), the colors of the positive part of the chart match with the legend (i.e. yellow upper and grey lower in both stacked bars and legend). However, for the negative values the legend is inverse to the actual order of the stacked bar (i.e. blue upper and orange lower in the staked bar but the opposite in the legend).
[Unsuccessful tries]
This is regardless of the actual data in the cells (changing the data doesn't change the colors or the order).
I've tried both changing the last parameter of the formula, and changing the order of the legend manually in the menu desing > select data > move up/down. None of them works, since it changes both the order of the stacked bars and the legends at the same time, so the order keeps unmatched.
[Question]
My question is, how can I match the order of the colors of the staked bars and the legend also for the negative part of the chart?
Example data:
1 -5
2 -1
3 1
4 5

Changing X axis scale in Excel

I have a X-Y scatter plot, my values in the x axis starts from the value 30.
How can i change the scale in the chart in such a way that I have values in the X axis starting from 30 and not zero?
I was able to do this in VBA as follows:
grab the chart object:
Dim objChart As Object
Set objChart = Sheets("MyWorksheetName").ChartObjects("MyChartName")
change the x-axis min value:
objChart.Chart.Axes(xlCategory).MinimumScale = myChartMinXValue
The x-axis in Excel charts seem to be called xlCategory. Also NOTE the MinimumScale property doesn't exist for all chart types. My first attempt was using xlLine but I kept getting an error. Once I switched to xlXYScatterLines VBA was happy.
right click the x-axis
select Format Axis
select the Fixed option next to Minimum and enter 30

Resources