Setting x axis scale in charts (1 Viewer)

Rachael

Registered User.
Local time
Today, 15:32
Joined
Nov 2, 2000
Messages
205
I want to overlay some charts (in a report) that are based on different queries but all contain a date field.

So far, I have thought I could acheive this by having an unbound form with fields to add criteria including a minimum and maximum date for the chart to display.

This min and max date would be past to the report to set the min and max time scale of the charts. By doing this I can overlay several charts to compare the different data but the time scale would match on each chart. Hope this makes sense so far.

Anyway does anyone know how to set the x axis values using parameters? The chart options don't like a parameter references entered into them.

Thanks,

Rachael
 

Rachael

Registered User.
Local time
Today, 15:32
Joined
Nov 2, 2000
Messages
205
this is what I have so far

Dim objChart as Object
Dim objAxis as Object
Set objChart = Me!NameOfYourGraph.Object

Set objAxis = objChart.Axes(2)

If objAxis.Type = 2 Then 'Type 2 = Value
objAxis.MaximumScale = 100
objAxis.MinimumScale = 0
End If

But I keep getting run time error 2771, the bound or unbound object frame doesn't contain an OLE object.

Is this a microsoft fault???


Thankyou Rachael
 

Rachael

Registered User.
Local time
Today, 15:32
Joined
Nov 2, 2000
Messages
205
Hi all, you will be pleased to know that after two days trawling the net for an answer I have solved the mystery.

Here's what I have learnt:

Tick the Microsoft Graph library box in VB references
Don't try to run the code in the report On-open as the OLE object (the graph) isn't actually open yet, put the code in the on activate event.
Move the graph from the detail section of the report to the header section
Fiddle with the Chart options axis settings (un-auto some things)
and finally, change the Dim objChart thing to Dim objChart As Graph.Chart

There!!

Hope this helps someone else in the future.

Rachael
 

Cosmos75

Registered User.
Local time
Today, 09:32
Joined
Apr 22, 2002
Messages
1,281
Rachael,

Thank you for posting what you found! I'm sure it'll come in handy someday!!
:D
 

vaporinc

New member
Local time
Today, 09:32
Joined
Jan 11, 2008
Messages
6
Thanks Rachael! You're a life-savior. I spent god knows how many hours trying to figure this out.

Now the only problem I have is with the Activate event. It works great when I just want to view the report. But I am automating the printing of the report and it doesn't work then. Anyone have any advise? The Open even will not work since the objects have not yet been created.
 

vaporinc

New member
Local time
Today, 09:32
Joined
Jan 11, 2008
Messages
6
I figured it out... on print event in the details section of the report instead of activate
 

SonicClang

Registered User.
Local time
Today, 09:32
Joined
Oct 14, 2008
Messages
16
I know this is a fairly old topic, but I found it extremely relevant to my current project. I work at an industrial manufacturing plant. The owner of the company told me he wants charts (line graphs) to print out at the end of each completed run of material through a machine. There are 6 charts that he wants on one page, and he wants the beginning and end of each to line up perfectly with one another so you can put a straight edge along the page vertically and match up changes to process parameters. I'm logging all the process parameters to a SQL database every 30 seconds and then querying the database by each run number, and that populates the charts. All that stuff was super easy. I chose to use Access to print the charts because its graphics engine is the most customizable that I've found. You can double click on a chart and resize areas by clicking and dragging. You can change font sizes. And best of all, you can use VBA to format the chart.

Like I said, I need the beginning and end of each chart to line up perfectly. The problem I ran into was that the values of each chart are drastically different from one another, AND the max and min values going into each chart can change from one run of material to the next. I've grouped the process parameters together into 6 charts because those items normally have similar max and min values, but every once in a while one of the parameters spikes WAY off the chart. Well, if the max value of the Y axis is set to Auto, it skews the entire chart and the other parameters are impossible to read, and more importantly, the numbers for the Y axis might change from 10's, to 100's, shifting the start of the chart over to the right a few pixels. So at first it appeared as though my options were to a) manually set a max value and risk having some of my data points go off the chart, and have the values of the lines less readable due to loss of resolution, or b) let Access set the max value automatically and risk having one bad value skew the chart.

What I was looking to do was set a minimum max value. If inlet temperature is less than 100, then set the max value of Y to 100. But if inlet temperature is greater than 100, set the max Y value to whatever the inlet temperature is. In the setup windows for the charts, this is not possible. But thanks to the code posted on this forum, I was able to modify it to fit my needs and accomplish my goal. Here's my code.

Private Sub Form_Activate()

Dim objChart1 As Object
Dim objAxis1 As Object
Set objChart1 = Me.gphTemperatures.Object

If Me.MaxOfInletTemp < 100 Then
Set objAxis1 = objChart1.Axes(2)
objAxis1.MaximumScale = 100
ElseIf Me.MaxOfInletTemp > 100 Then
Set objAxis1 = objChart1.Axes(2)
objAxis1.MaximumScale = Me.MaxOfInletTemp
End If

End Sub

And vwala, it works.
 

poduska

Registered User.
Local time
Today, 10:32
Joined
Jul 29, 2008
Messages
13
Thanks Rachael

The Chart Object and OnActivate was the trick for me to modify my chart within Access Forms
Thanks
 

Users who are viewing this thread

Top Bottom