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

Message ListMessage List     Post MessagePost Message

  Histogram with Tolerance Limits
Posted by Karl on Aug-05-2014 07:39
Attachments:
Hello,
I am attempting to create a histogram with tolerance limits.
I can't seem to get both the histogram (as a bar layer) and the tolerance limits (as marks)
on the same axis.
I am using Chart Director 5.1, on CentOS 6.4 using Qt 5.3.1 as my IDE.

If I code it this way:
   // Add labels
   xycHist->xAxis()->setLabels(DoubleArray(rBucketLabels, iBuckets));
   // Add a bar chart layer
   xycHist->addBarLayer(DoubleArray(rBucketPercent, iBuckets), 0x33CC33);

I get a very nice histogram (see picture1).

However if I try to add the marks, as in the following code, the marks are all bunched to the
low end of the X-Axis (see picture 2):

   xycHist->xAxis()->setLabels(DoubleArray(rBucketLabels, iBuckets));

   if (pLimits[iTest].bDynamicHi_V)
   {
      qreal rDyHi = pLimits[iTest].rDynamicHi * pow(10,pLimits[iTest].iScale);
      Mark *DyHi = xycHist->xAxis()->addMark(rDyHi, 0x0000ff,"DY HI");
      DyHi->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bDynamicLo_V)
   {
      qreal rDyLo = pLimits[iTest].rDynamicLo * pow(10,pLimits[iTest].iScale);
      Mark *DyLo = xycHist->xAxis()->addMark(rDyLo, 0x0000ff,"DY LO");
      DyLo->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bStaticHi_V)
   {
      qreal rStatHi = pLimits[iTest].rStaticHi * pow(10,pLimits[iTest].iScale);
      Mark *StatHi = xycHist->xAxis()->addMark(rStatHi, 0x00ff00,"ST HI");
      StatHi->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bStaticLo_V)
   {
      qreal rStatLo = pLimits[iTest].rStaticLo * pow(10,pLimits[iTest].iScale);
      Mark *StatLo = xycHist->xAxis()->addMark(rStatLo, 0x00ff00,"ST LO");
      StatLo->setAlignment(Chart::Top);
   }

   // Add a bar chart layer using the given data
   xycHist->addBarLayer(DoubleArray(rBucketPercent, iBuckets), 0x33CC33);

If I try to use "setLinearScale", the X-Axis gathers in the center of the chart and the bars of
the histogram disappear (see picture 3).:
    xycHist->xAxis()->setLinearScale(rScaledBuckets[0],
                                    rScaledBuckets[iBuckets - 1],
                                    rScaledBucketSize,0);

   if (pLimits[iTest].bDynamicHi_V)
   {
      qreal rDyHi = pLimits[iTest].rDynamicHi * pow(10,pLimits[iTest].iScale);
      Mark *DyHi = xycHist->xAxis()->addMark(rDyHi, 0x0000ff,"DY HI");
      DyHi->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bDynamicLo_V)
   {
      qreal rDyLo = pLimits[iTest].rDynamicLo * pow(10,pLimits[iTest].iScale);
      Mark *DyLo = xycHist->xAxis()->addMark(rDyLo, 0x0000ff,"DY LO");
      DyLo->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bStaticHi_V)
   {
      qreal rStatHi = pLimits[iTest].rStaticHi * pow(10,pLimits[iTest].iScale);
      Mark *StatHi = xycHist->xAxis()->addMark(rStatHi, 0x00ff00,"ST HI");
      StatHi->setAlignment(Chart::Top);
   }
   if (pLimits[iTest].bStaticLo_V)
   {
      qreal rStatLo = pLimits[iTest].rStaticLo * pow(10,pLimits[iTest].iScale);
      Mark *StatLo = xycHist->xAxis()->addMark(rStatLo, 0x00ff00,"ST LO");
      StatLo->setAlignment(Chart::Top);
   }

   // Add a bar chart layer using the given data
   xycHist->addBarLayer(DoubleArray(rBucketPercent, iBuckets), 0x33CC33);

If I add just the Marks when using setLinearScale, they are in the correct location and the
axis looks correct (see picture 4).

I also tried adding the marks on xAxis2, but I cannot get the two X-Axes to synchronize
(picture 5).

How does one add vertical marks to a bar layer?

Karl
picture1.tiff
picture1.tiff

111.31 Kb
picture2.tiff
picture2.tiff

128.61 Kb
picture4.tiff
picture4.tiff

99.76 Kb
picture3.tiff
picture3.tiff

106.36 Kb
picture5.tiff
picture5.tiff

145.34 Kb

  Re: Histogram with Tolerance Limits
Posted by Peter Kwan on Aug-05-2014 15:22
Hi Karl,

If you use Axis.setLabels, anything added on the x-axis are just treated as "labels", which
are text for human reading and ChartDirector would not try to understand what are those
labels. Labels can be anything. For example, "Apple", "Orange", "1.12748", "Monday" can
all be labels. Labels can duplicate and do not have to be "sorted" on the x-axis.

Internally, ChartDirector will just assume the labels are at x=0,1,2,3,..... regardless of the
actual text on the labels. If no x-coordinates are set for the bar layer, and it will also
assume the bars are at x=0,1,2,3,.... So the bars matches with the labels.

When you add mark, the x-coordinates on the mark refer to the label index. For example,
x=0 refer to the position of the first label. x=1 refer to the position of the second label,
and so on. x=0.5 refer to the mid-point between the first and second label.

For your case, if you would like to add a mark at the label 2.82, you would need to add it
using the index of the label as the x-coordinates. You can use a non-integer x-coordinate
if it is in between some labels. I think for your case, the index to the labels can be easily
computed using (in "pseudo-code"):

index = (markLabelValue - firstLabelValue) / widthOfEachBar

and the actual code would be like:

xycHist->xAxis()->addMark((rDyHi - rBucketLabels[0]) / (rBucketLabels[1] -
rBucketLabels[0]), 0x0000ff,"DY HI");

Hope this can help.

Regards
Peter Kwan

  Re: Histogram with Tolerance Limits
Posted by Karl on Aug-06-2014 01:30
Thanks Peter, that worked great.

Karl