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

Message ListMessage List     Post MessagePost Message

  Six Sigma Control Chart
Posted by Ed on Apr-19-2006 21:20
I would like to know if the ChartDirector can provide some sample code for building the six sigma control chart. I have heard the tools like 'Minitab' (http://www.minitab.com) or 'greenbelt xl' (http://www.gtpcc.org/gtpcc/greenbeltxl.htm) but they are not web app version.

Thanks!

  Re: Six Sigma Control Chart
Posted by Peter Kwan on Apr-20-2006 00:32
Attachments:
Hi Ed,

Some of our customers are using ChartDirector for SPC applications.

To draw SPC charts, there are two steps:

(a) Compute the statistics
(b) Display the result as a chart

ChartDirector currently is only performing (b). That is, you pass some numbers to ChartDirector, and it will return a chart visualizing the numbers.

For example, for a typical SPC chart like the attached ones, you would need to obtain the line data series, and to compute the UCL, LCL, positions, etc.. You may then pass these values to ChartDirector to turn them into charts.

Personally, I am not expert in SPC, but from my limited understanding of SPC, I think SPC computations are not difficult. (I have the impression that the SPC computations are designed to be computable by hand, so writing code to compute the values may not be difficult.) Once the values are computed, you may use ChartDirector to draw the charts.

Hope this can help.

Regards
Peter Kwan
spc2.png

  Re: Six Sigma Control Chart
Posted by Ed on Apr-25-2006 22:33
Thank you Peter for your help!

I have another question here. How I can show on a 'Guages Chart' based upon the a set of data (e.g. the data based on one column with 100 rows)?

-Ed
Peter Kwan wrote:
> Hi Ed,
>
> Some of our customers are using ChartDirector for SPC applications.
>
> To draw SPC charts, there are two steps:
>
> (a) Compute the statistics
> (b) Display the result as a chart
>
> ChartDirector currently is only performing (b). That is, you pass some numbers to ChartDirector, and it will return a chart visualizing the numbers.
>
> For example, for a typical SPC chart like the attached ones, you would need to obtain the line data series, and to compute the UCL, LCL, positions, etc.. You may then pass these values to ChartDirector to turn them into charts.
>
> Personally, I am not expert in SPC, but from my limited understanding of SPC, I think SPC computations are not difficult. (I have the impression that the SPC computations are designed to be computable by hand, so writing code to compute the values may not be difficult.) Once the values are computed, you may use ChartDirector to draw the charts.
>
> Hope this can help.
>
> Regards
> Peter Kwan

  Re: Six Sigma Control Chart
Posted by Peter Kwan on Apr-25-2006 22:56
Hi Ed,

I am not too sure what you would like to achieve.

A single meter or guage usually is for displaying one numbers (or a few numbers at most). I am not sure what you want to achieve with 100 numbers (1 column with 100 rows). Do you want to draw 100 points in the guage for 100 numbers, or 100 guages each displaying one number, or something else?

Regards
Peter Kwan

  DataSet with Line Chart help
Posted by Ed on May-04-2006 02:07
Peter,

I was wrong with the qestion that I posted and it supposed to be just couples of data for the Gauge chart.

I have another question for you. I saw that you have couple of examples for connecting to the database to retreve the data by using the following method:

DBTable table = new DBTable(sqlCmd.ExecuteReader());

What about I am having a dataset returned from the data source which have three different table data. Can I still use the method above and how?

Thank you for your help!

-Ed



Peter Kwan wrote:
> Hi Ed,
>
> I am not too sure what you would like to achieve.
>
> A single meter or guage usually is for displaying one numbers (or a few numbers at most). I am not sure what you want to achieve with 100 numbers (1 column with 100 rows). Do you want to draw 100 points in the guage for 100 numbers, or 100 guages each displaying one number, or something else?
>
> Regards
> Peter Kwan

  Re: DataSet with Line Chart help
Posted by Peter Kwan on May-04-2006 03:14
Hi Ed,

Yes. If you have multiple tables in a dataset, just use the table that contains the data you need to chart. For example:

//use the first table in the data set
DBTable table = new DBTable(myDataSet.Tables[0]);

If your data is in multiple tables, then you may create multiple DBTable objects to extract the data into arrays.

Hope this can help.

Regards
Peter Kwan

  Re: DataSet with Line Chart help
Posted by Ed on May-04-2006 04:13
Got it. Thank you for the help!

-Ed

  Re: Six Sigma Control Chart
Posted by Tom Clemmer on Aug-23-2006 21:31
I would be eternally grateful if you could post the code for this chart(PHP).  I think I could do it myself from scratch, but why bother if someone has already done the work.

I can calculate the data, just need the whole multichart thing.

Tom

  Re: Six Sigma Control Chart
Posted by Peter Kwan on Aug-24-2006 04:22
Attachments:
Hi Tom,

The original source code is in ASP, but I have just ported it to PHP. Attached please find the PHP source for your reference.

Hope this can help.

Regards
Peter Kwan
spc2.php
<?php
require_once("../lib/phpchartdir.php");

#Random number generator to create 301 values
$rantable = new RanTable(1, 1, 301);
$rantable->setCol(0, 100, -1, 1);
$data = $rantable->getCol(0);

#compute X and R in group of 3
$noOfGroups = (int)(count($data) / 3);
for ($i = 0; $i < $noOfGroups; ++$i) {
	$subgroup = new ArrayMath(array($data[3 * $i], $data[3 * $i + 1], $data[3 * $i + 2]));
	$X[] = $subgroup->avg();
	$R[] = $subgroup->max() - $subgroup->min();
}

$mR = new ArrayMath($R);
$mR = $mR->avg();
$mRUCL = 2.574 * $mR;
$mRLCL = 0.00;
$XBar = new ArrayMath($X);
$XBar = $XBar->avg();
$XUCL = $XBar + 1.023 * $mR;
$XLCL = $XBar - 1.023 * $mR;

#Create a XYChart object of size 600 x 550 pixels, with a pale yellow (0xffff80)
#background, a black border, and 1 pixel 3D border effect
$c = new XYChart(600, 550, 0xffff80, 0x0, 1);

#Set the plotarea at (55, 45) and of size 470 x 210 pixels, with white
#background. Turn on both horizontal and vertical grid lines with light grey
#color (eeeeee)
$c->setPlotArea(55, 45, 470, 210, 0xffffff, -1, -1, 0xeeeeee, -1);

#Add a title box to the chart using 11 pts Arial Bold Italic font. The text is
#white (0xffffff) on a dark red (0x800000) background, with a 1 pixel 3D border.
$t = $c->addTitle("X Bar R", "arialbi.ttf", 11, 0xffffff);
$t->setBackground(0x800000, -1, 1);

#Configure the axes
$c->xAxis->setTitle("Subgroup");
$c->xAxis->setLinearScale(0, count($X) - 1);
$c->yAxis->setTitle("Individual Value");

#Add a line layer to the chart for the data
$layer = $c->addLineLayer($X, 0xff);

#Put the xBar, UCL, LCL on the left y-axis
$c->syncYAxis();
$t = $c->yAxis2->setLabelStyle();
$t->setFontColor(Transparent);
$c->yAxis2->addMark($XBar, 0x8000, $c->formatValue($XBar, "Xbar:{value|2}"));
$c->yAxis2->addMark($XUCL, 0xcc0000, $c->formatValue($XUCL, "UCL:{value|2}"));
$c->yAxis2->addMark($XLCL, 0xcc0000, $c->formatValue($XLCL, "LCL:{value|2}"));

#Create another chart object for the range chart
$c2 = new XYChart(600, 270, Transparent);

#Set the plotarea at (55, 15) and of size 470 x 210 pixels, with white
#background. Turn on both horizontal and vertical grid lines with light grey
#color (0xc0c0c0)
$c2->setPlotArea(55, 15, 470, 210, 0xffffff, -1, -1, 0xeeeeee, -1);

#Configure the axes
$c2->xAxis->setLinearScale(0, count($R) - 1);
$c2->setXAxisOnTop();
$c2->yAxis->setTitle("Moving Range");

#Add a line layer to the chart for the range
$layer = $c2->addLineLayer($R, 0xff);
$layer->addDataSet(array($mRUCL));

#Put the mR, UCL, LCL on the left y-axis
$c2->syncYAxis();
$t = $c2->yAxis2->setLabelStyle();
$t->setFontColor(Transparent);
$c2->yAxis2->addMark($mR, 0x8000, $c->formatValue($mR, "mR:{value|2}"));
$c2->yAxis2->addMark($mRUCL, 0xcc0000, $c->formatValue($mRUCL, "UCL:{value|2}"));
$c2->yAxis2->addMark(0, 0xcc0000, "LCL:0.00");

#merge this second chart into the first chart
$d = $c->makeChart3();
$d->merge($c2->makeChart3(), 0, 300, TopLeft, 0);

# output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>

  Re: Six Sigma Control Chart
Posted by Tom on Aug-24-2006 06:47
Thanks Peter.

We have been using Chart Director for over a year now and the catch phrase we keep using at the office is, "There is nothing you can't do with Chart Director!"

Thanks for the code.  Saved me some time.

  Re: Six Sigma Control Chart
Posted by Juzer Mukadam on Sep-22-2009 22:49
Hi Peter,
I realize that this post is way late compared to the original thread, but we are in the process of analyzing the feasibility of using ChartDirector to create SPC Control Charts (XBarR and I&MR/XMR), preferably through a web-based Java application. (We already use ChartDirector for creating simple pie/line charts, but using ASP)


Could you help me out with a few pointers, as to how I can create an SPC chart similar to the one you have attached in your reply to Ed? (spc2.png)

Thanks for your help.


Best Regards,
Juzer

  Re: Six Sigma Control Chart
Posted by Peter Kwan on Sep-23-2009 09:00
Hi Juzer,

ChartDirector is a library to create general charts, such as line charts, bar charts, etc..  The line can represent the price of a stock, the temperature of a certain location, the revenue of a company, or the SPC statistics of a certain process etc.. One just needs to pass the data to ChartDirector, and configure ChartDirector how the numbers should be graphically visualized (as a line, bar, pie, thresholds, etc), and ChartDirector will turn the numbers into a chart.

Many of our customers are using ChartDirector for SPC control charts.

Note that ChartDirector will not get, compute, manipulate or modify your data. If you do not already have the SPC statistics, you would need to obtain or compute them first with your own code. After the staticstics are computed, your code can pass the data to ChartDirector to visualize them as a chart.

The sample code attached in this thread is the code that generates the chart in this thread. It contains two parts. The first part of the code computes the SPC statistics. The second part uses the data computed from the first part to create a chart.

Although I am not familiar with SPC, I think computing SPC statistics should not be difficult. The sample code in this thread computes X, R, xBar, mR, xUCL, xLCL, mRUCL, mRLCL from a sequence of random numbers, using only 13 lines of code.

Hope this can help.

Regards
Peter Kwan

  Re: Six Sigma Control Chart
Posted by Juzer Mukadam on Dec-31-2009 21:32
Hi Peter,
Had a couple of questions:
i. The above Chart Generation code which you have posted in PHP above, would you happen to have a similar sample copy written in Java. I could write it, but I wouldn't want to reinvent the wheel if it already is :) Thanks.

ii. Is there a way to save the image that is returned by ChartDirector on completing the request? Our application does not have a front end to it, and the business requirement is to save the returned image on another remote server once I have it from ChartDirector. Is that something that's possible through the API? I see in the getChart.jsp that GetSessionImage.getImage is called to render the image from the response


Thanks again.

Regards,
Juzer

  Re: Six Sigma Control Chart
Posted by Peter Kwan on Jan-01-2010 00:35
Attachments:
Hi Juzer,

I did not really have a Java version of the SPC sample code, but I have just translated the code for you. Please see the attached code.

To save the image as a file, you may use BaseChart.makeChart. For example:

c.makeChart("c:\\\\myChartImage.png");

Hope this can help.

Regards
Peter Kwan
aaa.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@page import="ChartDirector.*" %>
<%
	//Random number generator to create 301 values
	RanTable rantable = new RanTable(1, 1, 301);
	rantable.setCol(0, 100, -1, 1);
	double[] data = rantable.getCol(0);
	
	//compute X and R in group of 3
	int noOfGroups = data.length / 3;
	double[] X = new double[noOfGroups];
	double[] R = new double[noOfGroups];
	for (int i = 0; i < noOfGroups; ++i) {
	    ArrayMath subgroup = new ArrayMath(new double[] {data[3 * i], data[3 * i + 1], data[3 * i + 2]});
	    X[i] = subgroup.avg();
	    R[i] = subgroup.max() - subgroup.min();
	}
	
	double mR = new ArrayMath(R).avg();
	double mRUCL = 2.574 * mR;
	double mRLCL = 0.00;
	double XBar = new ArrayMath(X).avg();
	double XUCL = XBar + 1.023 * mR;
	double XLCL = XBar - 1.023 * mR;

	//Create a XYChart object of size 600 x 550 pixels, with a pale yellow (0xffff80)
	//background, a black border, and 1 pixel 3D border effect
	XYChart c = new XYChart(600, 550, 0xffff80, 0x0, 1);
	
	//Set the plotarea at (55, 45) and of size 470 x 210 pixels, with white
	//background. Turn on both horizontal and vertical grid lines with light grey
	//color (eeeeee)
	c.setPlotArea(55, 45, 470, 210, 0xffffff, -1, -1, 0xeeeeee, -1);
	
	//Add a title box to the chart using 11 pts Arial Bold Italic font. The text is
	//white (0xffffff) on a dark red (0x800000) background, with a 1 pixel 3D border.
	c.addTitle("X Bar R", "arialbi.ttf", 11, 0xffffff).setBackground(0x800000, -1, 1);
	
	//Configure the axes
	c.xAxis().setTitle("Subgroup");
	c.xAxis().setLinearScale(0, X.length - 1);
	c.yAxis().setTitle("Individual Value");
	
	//Add a line layer to the chart for the data
	LineLayer layer = c.addLineLayer(X, 0xff);
	
	//Put the xBar, UCL, LCL on the left y-axis
	c.syncYAxis();
	c.yAxis2().setLabelStyle().setFontColor(Chart.Transparent);
	c.yAxis2().addMark(XBar, 0x8000, "Xbar:" + (Math.round(XBar * 100) / 100.0));
	c.yAxis2().addMark(XUCL, 0xcc0000, "UCL:" + (Math.round(XUCL * 100) / 100.0));
	c.yAxis2().addMark(XLCL, 0xcc0000, "LCL:" + (Math.round(XLCL * 100) / 100.0));
	
	//Create another chart object for the range chart
	XYChart c2 = new XYChart(600, 270, Chart.Transparent);
	
	//Set the plotarea at (55, 15) and of size 470 x 210 pixels, with white
	//background. Turn on both horizontal and vertical grid lines with light grey
	//color (0xc0c0c0)
	c2.setPlotArea(55, 15, 470, 210, 0xffffff, -1, -1, 0xeeeeee, -1);
	
	//Configure the axes
	c2.xAxis().setLinearScale(0, R.length - 1);
	c2.setXAxisOnTop();
	c2.yAxis().setTitle("Moving Range");
	
	//Add a line layer to the chart for the range
	layer = c2.addLineLayer(R, 0xff);
	layer.addDataSet(new double[] {mRUCL});
	
	//Put the mR, UCL, LCL on the left y-axis
	c2.syncYAxis();
	c2.yAxis2().setLabelStyle().setFontColor(Chart.Transparent);
	c2.yAxis2().addMark(mR, 0x8000, "mR:" + (Math.round(mR * 100) / 100.0));
	c2.yAxis2().addMark(mRUCL, 0xcc0000, "UCL:" + (Math.round(mRUCL * 100) / 100.0));
	c2.yAxis2().addMark(0, 0xcc0000, "LCL:0.00");
	
	//merge this second chart into the first chart
	c.makeChart3().merge(c2.makeChart3(), 0, 300, Chart.TopLeft, 0);

	// Output the chart
	String chart1URL = c.makeSession(request, "chart1");
%>
<html>
<body style="margin:5px 0px 0px 5px">
<img src='<%=response.encodeURL("getchart.jsp?"+chart1URL)%>' border="0">
</body>
</html>


  Re: Six Sigma Control Chart
Posted by Juzer Mukadam on Jan-05-2010 01:44
Thanks Peter! This is exactly what I was looking for.

Will try out the image saving code, and will get back to you in case I run into any issue.

Thanks again.