5 Replies Latest reply on Jul 10, 2008 10:52 AM by Solerous

    Chart autoscaling behavior

    Solerous
      I am using letting the chart auto-scale for my program, however it seems to use a default minimum value of zero instead of something close to the lowest values of the chart. So since I have 15 series on this graph, they are all bunched up together at the top of the graph and it's very busy and unreadable. I know I could manually set the minimum value for each series, but the point of this program is for it to autoscale intelligently and apparently Flex's default behavior isn't working. Is there any other way to change the default behavior? Or do I just have to set the minimum values manually?

        • 1. Re: Chart autoscaling behavior
          matthew horn Level 3
          You're talking about Flex not generating acceptable values along the axes, right? Can you post a small example that displays this behavior?

          matt horn
          flex docs
          • 2. Re: Chart autoscaling behavior
            Solerous Level 1
            Sorry this is a little long. I actually cut out a lot of the code, but since I'm doing it in actionscript, it just takes more code to do.

            public function makeChart(genericChart:CartesianChart,
            genericLegend:Legend, chartPanel:ChartPanel, chart:ChartObject):void {

            var axisList:ArrayCollection = chart.getAxisList();

            var renderers:ArrayCollection = new ArrayCollection();
            var seriesArray:ArrayCollection = new ArrayCollection();
            var hAxis:DateTimeAxis = new DateTimeAxis();
            hAxis.autoAdjust = true;
            // define each axis
            for (var i:int=0; i<axisList.length; i++) {
            var axis:AxisObject = axisList.getItemAt(i) as AxisObject;
            if (axis.getID() == "x Axis") {
            var dMin:Date = axis.start;
            var dMax:Date = axis.end;
            hAxis.labelFunction = fullTimeLabelFunction;

            // more formating of the horizontal axis
            var ar:AxisRenderer = new AxisRenderer();
            ar.axis = hAxis;
            ar.placement = "bottom";
            ar.setStyle("canDropLabels", "true");
            ar.setStyle("tickPlacement", "none");
            genericChart.horizontalAxisRenderers = [ar];
            genericChart.horizontalAxis = hAxis;
            }
            else {
            var placement:String = axis.getLocation(); // usually 'left'

            // Define vertical axis
            var vAxis:LinearAxis = new LinearAxis();
            genericChart.verticalAxis = vAxis;

            // define series
            var lineSeries:LineSeries = new LineSeries();
            BindingUtils.bindProperty(lineSeries, "dataProvider", axis, "points");
            stroke.weight = 2;
            lineSeries.verticalAxis = vAxis;
            lineSeries.horizontalAxis = hAxis;
            lineSeries.displayName = axis.title;
            lineSeries.setStyle("lineStroke", stroke);
            lineSeries.setStyle("fill",stroke.color);
            lineSeries.xField="point1";
            lineSeries.yField="point2";
            seriesArray.addItem(lineSeries);
            }

            // more formatting of the axis
            var axr:AxisRenderer = new AxisRenderer();
            axr.axis = vAxis;
            axr.placement = placement;
            renderers.addItem(axr);
            }
            }

            genericChart.series = seriesArray.toArray();
            genericChart.verticalAxisRenderers = renderers.toArray();
            genericChart.percentWidth = 100;
            genericChart.percentHeight = 100;
            genericChart.seriesFilters = [];
            genericLegend.dataProvider = genericChart;
            genericLegend.direction = "horizontal";

            chartPanel.addChild(genericChart);
            chartPanel.addChild(genericLegend);

            this.addChild(chartPanel);
            }
            • 3. Re: Chart autoscaling behavior
              Solerous Level 1
              I finally tracked down in the documentation a couple of boolean values that can be set to fix this problem:

              vAxis.autoAdjust = true;
              vAxis.baseAtZero = false;

              Changing the baseAtZero is what fixed it for me.
              • 4. Re: Chart autoscaling behavior
                Solerous Level 1
                OOPS! I thought that was the answer but today I noticed that the scales are way off. What happens is that as I loop through each series and add it, that scale seems to override the previous one so that only the last series displays with the proper scale. To give you an example, using the tooltips, I can hover over two different series which intersect at the same point and one will say it has a Y value of 8.5 and the other of 9.7. I tried the autoscale flag, but that doesn't seem to fix it. Now what can I do?!
                • 5. Re: Chart autoscaling behavior
                  Solerous Level 1
                  Ok, my bad, I finally figured it out. If you look at my above code, I am creating the vertical axis WITHIN the loop so it keeps getting changed. That's the problem. When I pull this code:


                  // Define vertical axis
                  var vAxis:LinearAxis = new LinearAxis();
                  vAxis.labelFunction = formatVertLabel;
                  vAxis.autoAdjust = true;
                  vAxis.baseAtZero = false;

                  outside the loop, it displays properly.