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

Message ListMessage List     Post MessagePost Message

  chart director line chart adding dates for non existing values
Posted by Massimo Brillante on Nov-01-2013 18:19
Attachments:
Hi,

I am displaying a line chart with a dataset that has only 3 rows with 3 dates, however chart director displays 7 dates ???

I have attached a screenshot of the chart and the code to draw the chart; can anyone spot what I am doing wrong ?

Many thanks!
ACR.png
ACR.png

11.04 Kb
ACR_Code.txt
ACR_Code.txt

9.12 Kb

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-02-2013 02:45
Hi Massimo,

You may have already noticed that in the y-axis, there are 7 labels (0, 1, 2, 3, 4, 5, 6), but you only have 3 data points. Also, the labels may not be at the data point positions (there is a data point at around y = 5.3, yet there is no y-axis label there).

The above is completely normal. The number of labels may not be related to the number of data points, and the label positions may not be the same as the data values. For your current chart configuration, this applies to both the x-axis and y-axis. So it is normal that the number of x-axis labels is not the same as the number of data points.

In general, if the axis is a numeric or date/time axis, ChartDirector by default will auto-scale the axis to reflect the "data range". For example, if your data are from 1 to 5.3, ChartDirector may choose 0 to 6 as the axis scale and put labels at certain positions. However, if your data do not have a range (say all points are at y = 10.579321), ChartDirector would still generate a range for the axis (eg. from 0 to 20), as an axis must have a range.

For your x-axis, as I do not know your precise data, I can only guess. May be all your x-coordinates at at the same date/time, so there is no data range. ChartDirector therefore generate a range for the x-axis and determine the label positions. For example, it may create an axis range 1 minute wide, and put a label every 10 seconds. However, your code asks ChartDirector to use the date/time format "dd/mm/yyyy", so the "hh:nn:ss" part is not visible, and it ends up with duplicated labels on the x-axis, even though the actual date/time of the labels are different.

If you intend to use a true date/time axis (like what is being used in your current chart), and your data range can be very short (eg. less than 1 day), and you would like ChartDirector to automatically scale the axis, you may not want to use "dd/mm/yyyy" as the label format. You may want to use some label format that can show finer resolution.

If you would like the axis to span at least a few days (so that daily labels are appropriate), you may add dummy data that span a few days, such as an invisible transparent line layer with 2 data points several days apart. You may also use Axis.setDateScale to specify the date range you want on the x-axis.

If you just want the x-axis to display your x-coordinates as labels, please use Axis.setLabels, and not Layer.setXData. With Axis.setLabels, the labels are treated as names and displayed for human reading. They do not have any meaning to the computer. The data points would match to the labels one by one.

Hope this can help.

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo Brillante on Nov-05-2013 17:54
Hi Peter, thanks for your email.

You say "You may also use Axis.setDateScale to specify the date range you want on the x-axis."

should I use this after I call layer0.SetXData(dataX0)? or before this ?

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-05-2013 20:53
Hi Massimo,

You can use it on or after Layer.setXData.

However, note that if you use Layer.setXData or Axis.setDateScale, you should not also use Axis.setLabels. They represent two conflicting axis scale. The setDateScale means to use a date/time x-axis, in which the date/time of the data points are given using Layer.setXData. The Axis.Labels means to put "names" on the x-axis and the data points just match with the names one by one, and no x-coordinates (Layer.setXData) are required. (In the code in your last message, you seem to use both.)

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo Brillante on Nov-05-2013 19:01
but what I do not undertsand is that the Yaxis dataset has only 3 values and the Xaxis dataset that I pass has only 3 dates; so I think that if there is a way to say to chart director to not autoscale the Y values then also the xdates will not be autoscaled...

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-05-2013 23:47
Hi Massimo,

ChartDirector will only auto-scale if you use the axis (such as by adding data that are associated with that axis), but do not provide an axis scale. If you provide an axis scale (eg. using Axis.setLinearScale, Axis.setLogScale or Axis.setDateScale), then ChartDirector will use the provided scale and will not auto-scale the axis. This applies to all axes.

For example, if you call c.xAxis().setDateScale(minDate, maxDate, 86400), then ChartDirector will use the dates you specified for the x-axis, and not auto-scale the x-axis. Similarly, if you call c.yAxis().setLinearScale(0, 5, 1), ChartDirector will use the specified scale for the y-axis. So you can easily control which axis is auto-scaled, and which is scaled by your code.

In brief, if you do not want ChartDirector to auto-scale an axis, simply specify the scale you want to use for that axis.

Hope this can help.

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo Brillante on Nov-05-2013 20:40
Attachments:
I have added c.xAxis().setDateScale2(minDate,maxDate,data0Xlabels); to my code and fixed the issue I previously had, but screwed up other graph. Please see attachements
ChartDirectorACR.png
ChartDirectorACR.png

16.84 Kb
ChartDirectorBG.png
ChartDirectorBG.png

86.80 Kb
neCodeSnippet.txt
neCodeSnippet.txt

263 bytes

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-05-2013 23:51
Hi Massimo,

For your case, your code specify a lot of labels for the date scale. ChartDirector accurately follows what your code asks it to do, and put that much labels on the x-axis.

If you think there are too many labels, please use less labels, or you may let ChartDirector auto-scale the axis or automatically determine the labels (by not providing the third argument). If you only want to specify the labels when there is one date (in which case you seem to prefer an axis with one label), please only specify the label when there is one date (you can use an if/then statement to check), and so ChartDirector will auto-scale the axis in other cases.

Hope this can help.

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo Brillante on Nov-06-2013 02:21
Attachments:
Hi Peter,

I have added the attached code and now all charts do work properly; hopefully I am on the right path.
neCodeSnippet.txt
if (data0X.Length <= 10)
{
c.xAxis().setDateScale2(minDate, maxDate,data0Xlabels);
}

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-07-2013 00:45
Hi Massimo,

Depending how you compute the minDate, maxDate and dataXlabels, may be the following code would also work:

// Use the computed minDate, maxDate and dataXlabels only if there are 4 or less labels.
// If there are too many labels, let ChartDirector auto-scale the axis instead.
if (data0Xlabels.Length <= 4)
    c.xAxis().setDateScale2(minDate, maxDate,data0Xlabels);

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo on Nov-07-2013 00:58
Attachments:
Hi Peter,

I agree, however I found another issue; please consider that the code I am working with has been developed from another programmer who now left.

I am not aware why he is adding an extra value if min value and max value are out of the targets (see snippet below).

However when these values are added and the code hit the "setDateScale()" method there is an extra value added to the chart.

if the same values are added but auto scale kick in then the extra value is not added to the chart.

Probably for you to spot the issue I should send the whole code, but I feel like I am abusing your patience :-)
codeSnippet3.txt
codeSnippet3.txt

430 bytes

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-08-2013 01:48
Hi Massimo,

I suspect the "LowerTarget" is added because the original developer wants the LowerTarget to be include in the axis scale when ChartDirector auto-scales the axis.

ChartDirector will auto-scale the axis based on the data values. It will not consider other "decorative" mark up, such as a mark line. Suppose the original developer want to put a mark like at y = 100, but the data values are from 203 to 217. If ChartDirector auto-scales the axis, it is very possible that the axis scale would be something like from 200 to 220. In this case, the mark line at y = 100 is not visible.  The original developer wants the mark line to be always visible (that is, the axis scale always include 100 regardless of the data), but he also wants to use auto-scaling. One common method is to add a dummy (often transparent) data point at y = 100, so ChartDirector will consider this value when performing auto-scaling.

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo on Nov-07-2013 20:58
Attachments:
I am very close to the solution...

I am using SetLabels method rather than SetDateScale2 and all labels are sync with values...

however I have to display the area within  the values are OK and minimum and maximum target lines. When the min values or the max value is out of the range of the target a minimum value is added to the list of values. By using SetDateScale2 this value is not displayed on the chart but values and labels are not in sync.

I tried to add logic like if I use setLabels remove that extra value, but then the lower mark with the value of 50  is not displayed because I removed it :-)

so I am in a loop where I either get one thing fixed but not another!

I have attached 3 screenshots: one using setLabels, one using SetDateScale and one using SetLabels and removing the extra values needed to show min and max targets;plus the full chart code; if you could solve this puzzle for me I will get drunk this evening :-)

Of course this has nothing to do with chart director issues, is simply me not understanding how to properly use it in this case.
FullChartCode.txt
FullChartCode.txt

17.85 Kb
SetDateScale.png
SetDateScale.png

17.63 Kb
SETLABELS.png
SETLABELS.png

15.90 Kb

  Re: chart director line chart adding dates for non existing values
Posted by Massimo on Nov-07-2013 20:59
Attachments:
forgot the third screenshot
SetLabelsAndRemovingExtravalueForTargets.png
SetLabelsAndRemovingExtravalueForTargets.png

19.09 Kb

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-08-2013 02:07
Hi Massimo,

I have not studied your code in detail, but I speculate that the issue is because of adding the extra mark0 value to the data to be plotted.

Usually, we suggest to add the extra value to a separate dummy line layer, so as not to affect the data to be plotted. It is like:

//use the following if you are using Axis.setLabels
c.yAxis().addLineLayer(new double[] {mark0}, Chart.Transparent);

or

//use the following if you are using Layer.setXData or Axis.setDateScale
c.yAxis().addLineLayer(new double[] {mark0}, Chart.Transparent).setXData(new DateTime[] { data0X[0] });

There is no need to check if mark0 has already been included in your data, or if it is within the data range. You can just add it regardless of your data.

Hope this can help.

Regards
Peter Kwan

  Re: chart director line chart adding dates for non existing values
Posted by Massimo on Nov-11-2013 22:46
Peter Kwan wrote:

Hi Massimo,

......

//use the following if you are using Axis.setLabels
c.yAxis().addLineLayer(new double[] {mark0}, Chart.Transparent);

or

//use the following if you are using Layer.setXData or Axis.setDateScale
c.yAxis().addLineLayer(new double[] {mark0}, Chart.Transparent).setXData(new DateTime[] { data0X[0] });

There is no need to check if mark0 has already been included in your data, or if it is within the data range. You can just add it regardless of your data.

Hope this can help.

Regards
Peter Kwan

Thanks Peter; should I use those lines for the dummy values before calling Axis.setLabels and/or Layer.setXData or Axis.setDateScale?

  Re: chart director line chart adding dates for non existing values
Posted by Peter Kwan on Nov-12-2013 00:12
Hi Massimo,

It does not matter. They can be used before or after calling Axis.setLabels or Layer.setXData. If you use Axis.setDateScale, you should not need those lines (but they do not cause any harm if you add them anyway).

Regards
Peter Kwan