ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  it is a bug ?
Posted by cmings.chen on Aug-19-2013 01:01
Attachments:
running this code and change data value to see screen:

package Custom;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import ChartDirector.*;

public class simpleline
{
    public void createChart(ChartViewer viewer, int index)
    {
        double[] data = new double[2];
        data[0] = 34.38;//change the value to 134.38 and 127.46,it will get right on y axis.
        data[1] = 27.46;//when keep this value ,the y axis label will start at 0.it is right ?
how to hide zero and other unsuited label? how to detected i get a strange value broken
the chart?

        XYChart c = new XYChart(250, 250);

        c.setPlotArea(30, 20, 200, 200);
        c.addLineLayer(data);
        c.xAxis().setLabelStep(3);
        viewer.setChart(c);
        viewer.setImageMap(c.getHTMLImageMap("clickable", "",
            "title='Hour {xLabel}: Traffic {value} GBytes'"));
    }

    public static void main(String[] args)
    {
     simpleline demo = new simpleline();
        JFrame frame = new JFrame(demo.toString());
        frame.addWindowListener(new WindowAdapter() { public void
windowClosing(WindowEvent e) {System.exit(0);} });
        frame.getContentPane().setBackground(Color.white);
        ChartViewer viewer = new ChartViewer();
        demo.createChart(viewer, 0);
        frame.getContentPane().add(viewer);
        frame.pack();
        frame.setVisible(true);
    }
}
strange value.jpg
get right.jpg

  Re: it is a bug ?
Posted by Peter Kwan on Aug-19-2013 21:43
Hi cmings.chen,

What you see is normal. Both charts are correct and accurately reflect your data.

It is also normal that the axis scale is different if you use different data. By default,
ChartDirector will try to start the axis from 0 if the data range is large enough compared to
the data value, in which "large enough" means at 20%. This is configurable using
Axis.setAutoScale.

For example, if your data are from 4.9 to 7.8, the data range is 2.9, and ChartDirector may
choose a scale from 0 to 9, as it tries to start the axis from 0. However, if your data are
from 900004.9 to 900007.8, ChartDirector would not start the axis from 0, otherwise the
scale would likely be something like 0 to 1000000, and it is hard to see the small data range
of 2.9 in the chart. Instead, ChartDirector may choose something like 900004 to 900009 as
the axis range.

For your case, if your data are from 27.46 to 34.38, ChartDirector probably thinks the data
range is large enough compared to the data value, so it starts the axis from 0. If your data
are from 127.46 to 134.38, ChartDirector probably thinks the data range is too small
compared to the data value, so it does not start the axis from 0.

Hope this can help.

Regards
Peter Kwan

  Re: it is a bug ?
Posted by cmings.chen on Aug-19-2013 22:26
thank you ,i get a great help from you.

it seams like ChartDirector will calculate the least label? when the largest value minus least
value in ticks, if the result is less than the special value, it will be starting at 0, or the result
is greater than the special  value , it will be starting at a no-zero value.

  Re: it is a bug ?
Posted by Peter Kwan on Aug-20-2013 22:18
Hi cmings.chen,

For the detail method on how ChartDirector decides if the axis starts with 0 or not, you may
refer to the documentation on Axis.setAutoScale. The formula is listed in the
documentation.

Hope this can help.

Regards
Peter Kwan