|
Line Chart - How to prevent the line from displaying? |
Posted by Thom on Jun-06-2012 02:04 |
|
Peter,
I am using SQL to provide the data points for a line chart.
I am initializing each variable (ydata) within my jsp page to 0.
Everything is working as expected except when there is no data returned from SQL.
How can I prevent the line from displaying if I am using the following code to produce the
line? There must be another method to use.
double[] data0 = {ACR250, ACR500, ACR750, ACR1000, ACR1500, ACR2000, ACR3000,
ACR4000, ACR6000, ACR8000};
double[] dataX = {250, 500, 750, 1000, 1500, 2000, 3000, 4000, 6000, 8000, 8500};
// Set the labels on the x axis.
c.xAxis().setLabels(dataX);
c.addScatterLayer(null, new ArrayMath(data0).selectEQZ(new ArrayMath(
pointTypeACR).sub(0).result(), Chart.NoValue).result(), "AC (R)",
Chart.CircleSymbol, 13, Chart.Transparent, 0xff0000);
double[] checkArray = new ArrayMath(data0).selectEQZ(new
ArrayMath(pointTypeACR).sub(1).result(), Chart.NoValue).result();
c.addScatterLayer(null, new ArrayMath(data0).selectEQZ(new ArrayMath(
pointTypeACR).sub(1).result(), Chart.NoValue).result(), "AC (R) M",
Chart.TriangleSymbol, 13, Chart.Transparent, 0xff0000);
LineLayer layer0 = c.addLineLayer(data0, 0xff0000);
layer0.setLineWidth(1);
What am I doing wrong and how can I prevent lines from displaying when there is no data
being returned from SQL?
Thank you,
Thom |
Re: Line Chart - How to prevent the line from displaying? |
Posted by Peter Kwan on Jun-06-2012 04:08 |
|
Hi Thom,
Are the variables ACR250, ACR500, etc, values from your SQL? How it is possible to know if there is "no data returned from SQL"? If all of the values are 0, can I assume there is "no data return from SQL" (or is it possible the SQL just returns 0 as the data values)?
In any case, if there is no data, just use an empty array. For example:
double[] data0 = {ACR250, ACR500, ACR750, ACR1000, ACR1500, ACR2000, ACR3000,
ACR4000, ACR6000, ACR8000};
if (there_is_no_data)
data0 = new double[0];
If all zero values mean no data, you can just detect the all zero condition, and use an empty array. For example:
double sum = 0;
for (int i = 0; i < data0.length; ++i) sum += Math.abs(data[i]);
if (sum == 0)
data0 = new double[0];
Hope this can help.
Regards
Peter Kwan |
Re: Line Chart - How to prevent the line from displaying? |
Posted by Thom on Jun-06-2012 22:20 |
|
Peter,
In this case a user in our application has the ability to enter data and then have that data
plot on a line. If they select not to enter data for a specific point or any of the points, I
don't need the line or a specific pt (symbol) to display.
It is working just fine when the user enters all the data points. For example, if they only
select to enter 3 data points, the remaining points plot on the zero line which is incorrect.
This is occurring because I have to have the double [] variables initialized to 0.
Hope this helps and if you have any other recommendations, I would certainly appreciate it.
We are getting ready to purchase an open license if I can prove this will work as expected
as we have many other projects where we need CD.
Thank you,
Thom |
Re: Line Chart - How to prevent the line from displaying? |
Posted by Thom on Jun-06-2012 22:27 |
|
Peter,
Attached is an example of what is occuring to better explain the issue.
Data was only entered for 250, 500 and 750 but the remaining data points plotted a zero which is incorrect.
Thank you,
Thom
|
Re: Line Chart - How to prevent the line from displaying? |
Posted by Peter Kwan on Jun-06-2012 23:53 |
|
Hi Thom,
The data points are zero because your data values are zero. If you do not want the data points to be at zero, please make sure the data values are not zero. You may use Chart.NoValue if you do not want to have a data point in certain positions.
Hope this can help.
Regards
Peter Kwan |
Re: Line Chart - How to prevent the line from displaying? |
Posted by Thom on Jun-06-2012 23:57 |
|
Peter,
I am using using Chart.NoValue (see prev post same thread) but its not working as
expected.
Since double [] requires the variables to be initialized to 0, how might you suggest I handle
this on a point by point basis for the same line?
Thank you,
Thom |
Re: Line Chart - How to prevent the line from displaying? |
Posted by Thom on Jun-07-2012 22:03 |
|
Peter,
Thank you for all your assistance and recommendations.
I have it now working 100% as expected based.
I found an old post on the forum that you made last year the cleared up my understanding
of the use of Chart.NoValue.
This is a wonderful product that we will continue to use at our organization.
Thom |
|