Set JSChart visible x-axis - jscharts

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.

Related

How to do an Arrhenius plot using excel-VBA? AKA: How to do a reciprocal x-axis in excel-VBA?

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.

Scatter plot for variable number of rows and specific columns

I want to create an automated scatter plot. This is the first example table based on the step size I end up measuring A, B, C, D for a specific frequency. In this scatter plot I created manually you can see I want to plot C v/s A for a particular frequency.
But I need to do this automatically as based on the step size the number of row can change. Here, since the step size decreased the number of samples increased, and now the scatter plot needs to update number of A and C values it plots.
Is there a formula I can use without using any macros?
The relation between the step size and frequency is (number of samples of a single frequency = (360/step size)) so for a step size of 60 you will have in reality six entries of frequency 100 and six of 200 .
You can use formulas to define chart ranges if you hide the formulas in named ranges. Combine that with the fact that #N/A values are not plotted and you can get this to work without VBA.
For your example graph you could define two names ranges as follows:
Name: A_100
Refers To: =IF(Sheet1!$E$3:$E$100=100,OFFSET(Sheet1!$A$3,0,0,360/Sheet1!$B$1,1),NA())
and
Name: C_100
Refers To: =IF(Sheet1!$E$3:$E$100=100,OFFSET(Sheet1!$C$3,0,0,360/Sheet1!$B$1,1),NA())
Then set the X and Y axis of the chart to SheetName!A_100 and SheetName!C_100
The if statement filters out all the points not at frequency 100, if you have a formula for selecting the frequency replace "Sheet1!$E$3:$E$100=100" with that.
The offset function takes the first cell in the column and expands the number of rows according to your 360/step size formula.

Why does the units of Range.ColumnWidth not match either points or Centimeters (default unit used)

I am producing a VBA subroutine in an Access database which generates an Excel File however when I modify the column widths using:
Range("A:A").ColumnWidth = ...
Produces mixed results depending on the unit of measurement. Excel's default measurement set in options is Centimeters. I have tried entering the value in points and in cm but the result is either too wide or too small (see below):
Range("A:A").ColumnWidth = 3.07 'In Centimeters - Too small
Range("A:A").ColumnWidth = 87.02 'In Points - Too big
According to the documentation
Range.ColumnWidth
is set using the measurement in the points unit of measurement (width of 0). Regardless of the value I enter the result isn't the same.
The .ColumnWidth property refers to the number of zeros you can type in a cell in the default font without exceeding the cell's width.
In a new workbook where presumably your default column width is 8.43, type '000000000 in a cell and you'll see that the 9th zero overflows the right cell border by about half a zero.
To set the cell width in points, set .ColumnWidth to points / cell.Width * cell.ColumnWidth. Here's the catch, you have to set it three times to get it close, but it will almost never be exact. So put the .ColumnWidth assignment in a For Next loop and set it three times.
Note that the .Width property is in points and you can't set it. The .ColumnWidth property is in crazy-zero-width-measurement and you can set it. Why it takes three times, I don't know.
See http://dailydoseofexcel.com/archives/2004/06/01/column-widths-in-points/ for some test results on the 'three times' thing.

Setting maximum and minimum values for x-axis in Excel

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.

Excel vba: Axis minimum scale sometimes doesn't get updated on chart

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

Resources