Is it posible to get the position of point on an excel graph axis - vba

I'm not sure this is possible but thought this was the best place to ask.
Is it posible to get the position of a series value on a graph in excel?
For example, if I have a line graph in excel that has time along the x axis, is it possible to (using VBA) get the position of a specific point on that axis.
What I am trying to do is have a vertical line that is can be positioned based on a date entered by the user.
like this
Where the green line could be positioned by entering in a date (rather than just being manually moved) (or also it could be set to automatically move to the current date etc).
I was then thinking that if the position is on the graph is queryable, then I can just access the line object and move it to any position I wanted through VBA.
Any Ideas? or is this just not possible?

The "cleanest" way to do this is to add the line to the chart as a new series. In that way, Excel handles all of the positioning and your work is simplified. To get a vertical line on a chart, there are a number of options. I prefer this route:
Create a small 2x2 area with two dates and two values
Add in the date or x-axis value you want the line at (E3 in image). You can use =TODAY() here or some manually entered value.
Set the second x-axis value equal to the first
Use MAX and MIN on the data to get the values for each date. You can also use 0 and 1 and a secondary axis, but I think MAX/MIN is easier.
Add the data to the chart and format as a marker with straight line.
Formulas
E3: =TODAY()
E4: =E3
F3: =MIN(C3:C27)
F4: =MAX(C3:C27)
Result and chart data series for vertical line

Related

Is it possible to add a horizontal line to an infragistics ultraSparkLine that isn't an average

I am new to using infragistic controls. I have added a ultraSparkLine to a VB 2017 application. I am doing it using in Area format. It is displaying work being accomplished during time frame. Want I would like to do is add a horizontal line that would show target rate of what is expected as work rate. I see I can have the Trendline but that seems to show average work rate for time frame being displayed.
Is it possible to add a horizontal line at a predetermined value?
There is no build in way to draw horizontal line. However you can use normal range to make something like a horizontal line. First set minimum and maximum to your chart. This will allow you to show the horizontal line above/bellow the spark line. Then set NormalRangeMaximum and NormalRangeMinimum to some very close values. For example if minimum is 0 and maximum is 100 I would set the ranges to let say 89.9 and 90.
As a final touch you can set NormalRangeFill to some brush as needed in your application.

Changing graph range based on specific cell data

See image for what I have going on
So the red column will at some point, which is different every day, change from 20 to 50. The start cell up top uses that lookup formula to find when this is. So for this example it is 10/11/16 14:37. I want to graph the green and blue columns, starting at that cell time and ending at the end time (which is just a max() of the times to get the end time).
I've looked into offset and name manager but I am really confused on those. Either using VBA or something else to change the graph (on a different sheet) to start at whatever that start time is would be awesome.
You can try the following:
In the column AL set, in each cell, the value to be defined by the following formula
AL1 = IF(AI1<50,0,1)
AL2 and following = IF(AL1=1,1,IF(AI2<50,0,1))
Then define each AM to be AL*AK, and plot AM.

SSRS line chart

I have one question to the line chart.
I would like to create a line chart, which values are given. It should look like this chart here:
My question is, how can I implement this. I tried to put it as a stripline in the chart but it only shows a horizontal line without this steps at the beginning.
How can I create this line chart like in the picture above?
can I put into this:
the values.
Striplines are intended to display just a line across the chart, or varying width, height, to demonstrate an area... from MSDN
Strip lines, or strips, are horizontal or vertical ranges that shade the background of the chart in regular or custom intervals
To get the behaviour (I think) you require you can add a new series to the data you are returning with each of those datapoints. Irrespective of what other data you are charting, you can change the type of this series to Line Chart, and change the order of the series on teh chart to make it uppoermost.
Without further information - such as the data you are tyrying to superimpose this on - it's hard to advise further.

Flexible Data Label Formatting

I'm hoping to add custom data labels to a stacked bar chart in Excel 2010. Each bar will have a label value pulled from a value in the sheet which is not necessarily equal to the height of the bar itself.
The sheet I'm making is a template and has drop-down selections to change the units of the data. For example: $MM with 1 decimal point, K with 2 decimal points, $ with 0 decimal points, etc... I'm running into an issue formatting the labels to match the data formatting selections. I've tried two approaches:
Formatting the data labels themselves using VBA. Partial code below for $K with one decimal:
`With ActiveChart.SeriesCollection(x).Points(y)`
.DataLabel.Text.NumberFormat = "$#,##0.0,"
Unfortunately, the labels don't seem to read the commas and divide by one thousand, so I can't accurate display thousands or millions. A value of 1000 in the above code will display as $1,000.0 instead of the desired $1.0.
Format the values in the worksheet, and then just read them with VBA. Basically, I use conditional formatting to properly display the values on the sheet, and then read them with .DataLabel.Text = Cells(r,c)
Unfortunately, though the data is formatted correctly, the values are unchanged and the labels display with no custom formatting at all.
Is there any reasonable way to achieve my goal? I'm hoping there's a way to either (1) make commas count when changing data label number formats or (2) change the actual values of the data in my sheet based on the formatting drop-down selections (instead of just giving them custom formatting which leaves the value unchanged).
Thank you,
Lance
I think the words "conditional formatting" are your issue here: I've had problems with VBA reading the underlying format of a cell when it's conditionally formatted (admittedly, my issue was with colour, rather than number format, but I expect the reasons for it not working would be the same).
If you adopt your second approach, i.e. relying on the worksheet's format using the chart's "Linked to source" option, then on a trigger of when the drop-down option is changed, you could use VBA to set the format on the worksheet instead of using conditional formatting - then the chart would pick up whatever format you're using.
Please try this:
?Format(1000,"$#,##0.0,")
$1.000,0
?Format(1000,"$#,##0,.0")
$1,0
?Format(1234,"$#,##0,.0")
$1,2

Creating a line in an excel chart which always shoots a red line through todays date in VBA

I have a chart which I would like to always run a line through today's date after I run a Macro I am working with. I would also like it to say Today right above the chart and above the red line. I would like to code this out in VBA but I don't really know where to begin. I have the chart Does this make sense? Thanks.
Read through this and combine with =TODAY().
Edit: The specific formula you'd be using for your column of vertical lines is
=IF('cell in same row containing date'=TODAY(),MAX('range of your data'),"")
This formula will return the max from your list of data if the date in your table is today's. If you follow the instructions for option 2 from the link and create another data series for vertical lines and put this formula in that column, you will have a vertical line that is always on today's date.
One more Edit: To address having "Today" above the line, add data labels to your "Today" series by right clicking on the series and going to "Add Data Labels." Right click on the Data Labels and go to "Format Data Labels." Go to "Number" and select Custom. Enter "Today";;; into the Format Code box and click add. Your Data Labels for your blanks should go away and your date line should have "Today" over it. Format it however you wish.
And if you want to make this part of a macro, record it and play around with the code you get until you find something that works. IMO, just having this as a part of your chart is easy enough.
Last edit I swear: If your line is too fat, right click on the series/line, go to "Format Series," change the fill to a gradient, set the rotation to 180*, and play around with the stop positions and transparencies to make the line appear thinner. That's all I've got, so if I've helped in any small way, mark this as useful.