I have a gui that provides min and max values for a selected axis, like the following for the x-axis:
'X-axis
If ListBox8.ListIndex = 0 Then
ActiveChart.Axes(xlCategory, xlPrimary).MaximumScale = TI_Chart_Tool.MultiPage1.Pages(2).TextBox2.Text
ActiveChart.Axes(xlCategory, xlPrimary).MinimumScale = TI_Chart_Tool.MultiPage1.Pages(2).TextBox3.Text
End If
At the time this occurs, the x-axis of the chart, should change accordingly, right? Initial passes, for both x and y axis, seem to work fine, while testing, i seemed to get into a state such that the chart values would only be updated, when i clicked on the chart area.
(Let me add, this state seems to occur after i change the y-axis to a logarithmic scale.)
Does anyone know how to always have the axis values be updated automatically, from within the code without having to click on the chart?
Thanks for any help!
Russ
Related
Is there a way to set the visible x-axis range in JSChart despite the range of the data set?
I use JSChart to draw a line chart. The x-axis is date. The y-axis is an integer value (from 0 to 100).
Let's save x-axis min value is 2000-1-1 and max value is 2010-12-31).
Is there way way to configure JSChart to show only the part of data say (2005-1-1 to 2006-1-1)?
I have tried doing
config.data = myData
config.options.scales.x.suggestedMin = start
config.options.scales.x.suggestedMax = end
where start is 2005-1-1 and end is 2006-1-1. But JSChart still show my data from the beginning, i.e. 2000-1-1.
see this ref:
suggestedMin only change the data values that are used to scale the axis.
To change the explicit ends of the axis, use min and max.
I want to write a program to transform temperature dependend data into an Arrhenius plot. An Arrhenius plot show the logarithm of a property that is thermally acitavted versus the reciprocal temperature aka 1/T. Now is 1/T something that most people are not used to. This is why most of the plot also contain the translation in temperature on a second axis. Usually on top of the graph. The output should look like this:
Picture Source
The second axis is only for better readability and is corresponds to the primary axis with the relation:
primary=1/secondary
secondary=1/primary
What I am not able to do in excel-VBA (excel 2010) is the reciprocal second x-axis. There is no predefined axis scaling like this. There is xlScaleLinear and xlScaleLogarithmic for the property ScaleType of an axis. Is there a way to do this?
A secondary problem is that this:
Dim CH As Chart
Set CH = Tabelle2.ChartObjects(1).Chart
CH.ChartType = xlXYScatterLinesNoMarkers
With CH
.HasAxis(xlCategory, xlSecondary) = True
End With
Does not seem to work. Which means that a xyScatterplot does not seem to have a secondaryXaxis enabled.
I could try to add the lables and ticks myself using forms but this seems a little to much pain, I cannot be the only one who has encountered this problem.
Problem 1: How to format an axis reciprocal (1/x)?
Problem 1b: How to properly add a second x axis in a XYscatterplot?
You can do this by creating a fake axis using a series with data labels (inspired by https://peltiertech.com/secondary-axes-that-work-proportional-scales/):
Columns A and B are your data. Column C matches the X-ticks of your primary X-axis. Column D is =1/C2 etc and column E is the y-axis maximum for your chart. Now simply create a new series of columns C and E, format it to have no line and in this case I chose the + marker but you can create your own vertical line marker if you want it to be exact. Then add data labels set to range column D.
I don't think you'll find another way to do it without this hack, but it's really not that hard and doesn't require VBA which is always a plus in terms of readability / audibility of your workbook.
Another alternative would be to use the data labels to write the actual temperature to the data points:
Column C has the temperature in Celsius.
Since the Arrhenius plot is only defined as ln(k) against 1/T, this would be a good option I think.
I wish to customized the Y-axis to text instead on value.
Is there any way I can do it without any plugin?
Here will be my data:
A B C D
1 Lower Limit Upper Limit # Data
2 30S 40S A1234 30A
3 30S 40S A2345 30S
4 30S 40S A1256 30S
I wish my Y axis will be 30S, 30A, 40A, 40S intead of 10,20,30,40
and my X axis will be A1234,A2345,A1256
Is there any possible that I can change the X axis value?
I started with your data, and I added a small lookup table. I inserted a column "Value" (blue text) in your data range that has the Y value corresponding to the label in your "Data" column. You can use a lookup formula for this, for example, the formula in D2 is:
=INDEX($H$2:$H$5,MATCH(E2,$I$2:$I$5,0))
I made a column chart (don't know what type of chart you want, but this technique is widely applicable) using the yellow shaded range in the first data range (top left chart). I selected and copied the green shaded range in the second data range, selected the chart, and used Paste Special to add the data to the chart, using the settings shown in the dialog overlying the top right chart.
This has added another set of columns (bottom left chart), not so useful. I right-clicked the added series, picked Change Series Chart Type from the pop-up menu, and changed just this series to an XY scatter type (bottom right chart).
The XY scatter series is on the secondary axis, also not too useful. I formatted the XY series, and changed the axis to Primary (top left chart below). The 0.5 values in column G make the points line up with the vertical axis of the chart.
I added data labels to the XY series, shown in orange to distinguish them from the black axis labels (top right chart below). I formatted the labels so they appear to the left of the points, and so they used the Value from Cells option, based on the labels in I2:I5 (middle left chart below). If you don't have Excel 2013, you don't have this option, but you could
Manually type the desired text into the labels.
Link each label to the desired cell: select the labels (one click), select the desired label (second click), type = in the formula bar, select the cell, press Enter, repeat for all labels.
Use a third-party add-in like Rob Bovey's free Chart Labeler from appspro.com.
I hid the default axis labels. You can select None for axis labels, and then resize the plot area to make room for the custom labels created above. But I used a custom number format for the axis, which consisted of several space characters enclosed in double quotes. See middle right chart below.
Finally I rescaled the vertical axis so its min and max were 0 and 40 and the major spacing was 10, I formatted the XY series to use no markers, and I changed the label font color back to Automatic (bottom chart).
I have a graph that has dates on the x-axis and I'm trying to set maximum and minimum values for this axis using an Excel VBA. I defined MinXAxis and MaxXAxis values in the same sheet and here is my code:
Sub UpdateChartAxes()
With ActiveSheet.ChartObjects("Chart 1").Chart
.Axes(xlCategory).MinimumScaleIsAuto = False
.Axes(xlCategory).MinimumScale = Range("MinXAxis").Value
.Axes(xlCategory).MaximumScaleIsAuto = False
.Axes(xlCategory).MaximumScale = Range("MaxXAxis").Value
End With
End Sub
When I run this code I get error 400 with no explanation about the error.
Any ideas what might be going wrong?
Axis.MinimumScale Property
Returns or sets the minimum value on the value axis. Read/write
Double.
You should be applying these properties to the value axis xlValue, not the Category axis.
Setting this property will also set MinimumScaleIsAuto = False so you won't need those lines.
Added If you use a column, bar, line, etc., graph then these have a Value and a Category axis. You can only set the Minimum or Maximum for the Value axis. Even if you swap them around (x - y) there is still only one Value and one Category axis. Edited An exception to this is if dates are used as the Category axis, in which case Excel enables the Scale settings, as it recognises them as values.
If, instead, you use a Scatter graph, then this has both X-Values and Y-Values, and each of these value axes can be given maxima and minima.
By far the easiest way to prove all this is to double click on an axis and see whether the Axis Options allows you to set a minimum and maximum.
At the beginning of the code, add
On Error GoTo ShowErrDescription.
After End With and before End Sub, add the following code
Exit Sub
ShowErrDescription:
MsgBox Err.Description
This should at least give you a little more information about the error.
In previous versions of Excel there was a registry entry that you could create to allow Excel to display values/labels that would be positioned outside the axis min/max using QFE_Bonn dword=1. This is what I have used for Excel 2003: Plot lines that contain labels disappear ...)
I have not been able to find a similar patch or native functionality in Excel 2010 (Office Pro Plus). Any ideas how this can be accomplished, or did MS remove this functionality altogether?
Here are screenshots of examples in Excel 2003. I create a series of data which uniformly exceeds the y-axis maximum. This series' color fill has been removed already
To finish the look, remove the series' border so that it appears invisible. Then replace the series' value labels with the relevant data.
There is a workaround using the DataLabels.Left property which positions the DataLabel relative to the ChartArea.
Here is an example VB solution:
sub FakeLabels()
Dim sF As Double
Dim lOff As Double
Dim p As Double
ActiveSheet.ChartObjects(1).Activate
With ActiveChart
For sF = 1 To .SeriesCollection.Count
If .SeriesCollection(sF).Name = "FakeSeries" Then
'Define the lOff variable by adding 100, or some other value
lOff = .SeriesCollection(sF).Points(1).DataLabel.Left + 100
For p = 1 To .SeriesCollection(sF).Points.Count
.SeriesCollection(sF).Points(p).DataLabel.Left = lOff
Next p
End If
Next sF
End With
It yields the same results, the only new requirement is to keep the values for the "dummy" series within the axis min/max values for the chart.
A pleasant surprise is that re-sizing the chart doesn’t appear to affect the relative placement of the labels.
UPDATED 9-25-2013
I have used the "textbox" approach since first asking this question. But it is extremely clunky to manage the interplay between the labels' position and the textbox positions, their relative position of the PlotArea i.e., when to use .InsideWidth vs. .Width or .InsideLeft vs. .Left and whether there needs to be any sort of hedonic "adjustments" to the points values, as always seem to be the case, they are never quite perfectly aligned.
While perusing the PPT object model reference for some other chart-related inquiries, I stumbled upon this property which appears to replicate the functionality of the previous hotfix/registry hack.
.ShowDataLabelsOverMaximum