Automate graph generation based on variable time - vba

I need help creating an Excel macro.
I want to take the Excel file here and create a graph of each of the servers with time being the x axis and memory utilizaiton % being the y axis. The problem is, the number of data points for each server can be variable (sometimes the first server has x number of data points, other times it has x+2).
Can anyone help me with this?

Sure. If I'm understanding correctly, you need to create a chart where your data can grow in size. In that case you need to use a "dynamic named range" that expands as new data is added. The chart that you will end up creating is called a "dynamic chart". The dynamic range is set up using the OFFSET function which allows it to expand.
I think these videos will help you:
Excel 2010 / 2007: http://www.youtube.com/watch?v=M9hhUVljTx4
Excel other: http://www.youtube.com/watch?v=7le-m8YRP6M

Related

Database to Excel charts (or pdf)

Hi guys I have a simple DB that has two fields in it (time and number 1-3), the data needs to be exported and shown in simple charts (horizontal bars from 0 to max time from my DB)? What is the best way to do that?
The easiest was to establish a direct data access from excel to SQL-Server and use Excel's abilities for the graphics.
If you need the data "exported", it is quite easy to get a table as CSV-list. Again this can be opened with Excel directly to do the graphical work there.
Depending on your environment you might think about any reporting tool, obviously the first choice was SSRS or PowerBI, which is part of the box.
You might even use a SELECT * FROM YourTable and just copy-and-paste the full result into Excel.
The main things to think about:
One-time action or regularly
Grade of automatism
Size of data / Count of rows
Location / Access-rights / Linkability of your systems
Existing tools

Using VBA to scale excel graph X-axis?

I'm using a macro to generate graphs from a table such that the x-axis is a time stamp(date, time) and the y-axis is for the data at that time. So far, there is no problem getting this to work but the result is a graph that has "blank space" before and after the data(roughly 5-10 minutes before and after on a 1-hour time-frame). I have space constraints and this cuts into them so I'd like to utilize the entire plot area. Can I eliminate the blank space by extending the data to end of the plot area somehow? Any help is appreciated.
Additionally the files I need to use are for different time frames and lengths of time(ie, different length of excel rows). Is there a way to only graph the rows with content instead of a "worst-case scenario" like using A2:A100000 because I know it will never be greater than 100,000 rows?

Programmatically creating multilevel axis chart with VBA on Excel

I have some code that retrieves data from a SAS Table on a server. I'm trying to chart this data using VBA, without copying it to an Worksheet first (Feeding the recordset directly into the charts)
I've had success so far with this. The problem is, my charts need to have multilevel categorical X axis, and i'm having trouble automating this only with VBA
What I'm trying to get is something like this
http://imgur.com/ElwHwjE (I can't post the image due to lack of reputation)
But so far all my attempts lead to this
http://imgur.com/id7Vua0
I know I can do this if I first make a Pivot Table from my recordset and then build a chart on top of it, but as stated before I'm trying to do this without copying the data into a Sheet.
Also tried messing with TickLabel options (Multilevel and Depth), but so far to no avail.
I've tried everything I could think of, and I have not been able to create a multiple level categorical axis without having the axis data in a worksheet. I've tried various 1D and 2D arrays, with array elements that include various LF, CR, and CRLF characters. I've tried using the worksheet range, then converting XValues to an array, and of course, this broke the axis without providing a usable array.
Bottom line: Excel charts were designed to plot worksheet data, and you can't always get around this requirement. Most of the time I think you shouldn't waste time trying to get around it.

bind Data table to chart in vb

I have a project that im working on at the moment in VB.
Basically I have a Data Table in VB it populates with 4 columns and a variable number of rows, the column names are as follows;
Gear, RPM, Speed, CO2
The data table appears in datagridview correctly but that's as far as I have gotten :/
What I am trying to do is to make a line chart called mainGraph to draw a graph based on these results, I'm getting stuck when trying to populate the chart.
ANY thoughts would be really appreciated.
I am guessing you are using the ms chart controls and not some 3rd party like Telerik.
This should be usefull http://blogs.msdn.com/b/alexgor/archive/2009/02/21/data-binding-ms-chart-control.aspx
Also, there is source code found at http://archive.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=4418
in short this is a way to get things displayed
mainGraph.Series(0).ChartType = DataVisualization.Charting.SeriesChartType.Line
mainGraph.Series(0).Points.DataBind(yourDataTable.DefaultView, "Speed", yourDataTable.DefaultView, "Gear")
These commands should make a line graph with Speed on your x axis, and Gear on your Y. Assigned to "Series(0)"
To add more columns, you need to add more "Series"
mainGraph.Series.Add("RPM")
Do some thinking about how you want this data displayed.
how would you like to set this graph up?
I'm assuming you would want a line graph?
What is going to be the X axis? Is there a missing column that needs to be "time" in the data table?
do you want them all on one graph/chart area?
If you would like more charts, then you need to add chart areas. A series can be assigned to a chart area.
Hopefully this helps.

Excel 2007 - External Datasources (Tables) Changing Absolute Ranges

Excel 2007 is driving me nuts. I have several charts set up that I refresh periodically against some data in a SQL database. However, every time I refresh them, Excel bumps any absolute ranges I have for the charts to view this data by the amount of new records returned from the query.
The data is time related (I have a record for each minute of the day), and I want the chart (line chart) to be fixed in size... instead, Excel wants it to dynamically change, and thus it adds the extra rows to my named ranges.
Is there a way to prevent Excel from updating absolute named ranges when new data from a data source is returned? I hope this makes sense.
How are you defining your named ranges? I'm assuming your are just using cell references, if so it may be worth looking at the offset function, particularly if you are dealing with fixed size ranges (e.g. minutes in a day).
For example, if you had column headers in the first row, your minutes were in column A and you had exactly 1 row for each minute your offset formula would look like:
OFFSET(A2,0,0,1,1440)
and is defined as
OFFSET(StartCell, OffsetRows, OffsetCols, Width, Height)
Because any of the values within the arguments can also be formulas, OFFSET is a very useful function in defining ranges.