6 Replies Latest reply on Jun 2, 2011 10:20 AM by guest contributor

    Programmatically set date axis range

    Andrew Thacker

      Hi

      Relatively new user here ... stuck trying to force the x and y axis of a scatter plot to have the same range, but determined programaticaly.

      In this case I have dates on both axis.

       

      I can see in the axix dialoge box that I can set the range manually by specifying dates ... but I need the range of both axis to be set dynamically, but always equal.

       

      So I don't think I can do it via the dialogue box.

       

      I have an intutive feel I need to create some table calculations to work out the max and min dates values in my selected data set, and somehow use these to drive the range of the axis ... but this is where I am stuck.

       

      Thanks

      Andrew

        • 1. Re: Programmatically set date axis range
          Richard Leeke

          Will the actual range of X and Y values be the same - or do you want to force the axes to span the widest value in either dimension?

           

          If the actual values had the same range I would have thought Tableau's automatic range setting would do what you want - so presumably that is your issue.

           

          The only trick (and I use the word deliberately) I can think of which might help is as follows.  Others may think of other options.

           

          If you define yourself two calculated fields: [DateMin] and [DateMax] (say), you can define reference lines on both axes using these fields.  You can make the reference line invisible by specifying None for everything that shows (line, label, etc) but Tableau will still adjust the axis scale to include the position of the reference line.

           

          This only works if you want to extend the ranges out further than your data values - Tableau auto-sizes to include marks and reference lines.

           

          Also, this doesn't let you say I want the scale to start at 27 minutes past 3 on 4th April - Tableau will still round to what it regards as a sensible cut-off.  Usually that is fine, but it sounds as if you may have fairly particular requirements.

          • 2. Re: Programmatically set date axis range
            Andrew Thacker

            The invisible reference lines idea is great.

             

            I had already tried calculating a max and min date ... but was stuck to know what to do with them to force to the scale  ... the invisible reference line suggestion sounds perfect.

             

            Thank you

            -

            • 3. Re: Programmatically set date axis range
              Andrew Thacker

              I also just worked out for myself to ADD the y axis date values, as a SECONDARY x axis, and to force synchronisation ...

               

              ... this results in the x axis dates being effectively forced to follow the range of the Y axis dates,

               

              this works, but I think the Min, Max, Reference lines gives more programmatic programming options.

              • 4. Re: Programmatically set date axis range
                Richard Leeke

                Good idea - but doesn't that give you a diagonal set of marks from (Xmin, Ymin) to (Xmax, Ymax)?  Or have you hidden those too?

                 

                Or maybe my mental image of what you're doing is off track.

                • 5. Re: Programmatically set date axis range
                  Andrew Thacker

                  Actually, the diagonal line is part of the requirement ... but it was just luck that it turned out that way.

                  The chart is a Milstone Tracking Chart.

                  • 6. Re: Programmatically set date axis range
                    guest contributor

                    I would like to do something similar but with values instead of dates.  I would like to set the Y-axis max value to be a certain value, this would allow me to eliminate plotting bad data.  Do you have a sample visual of the calcaluation and worksheet you can share?