Widget development

Viewpoint
Teradata Employee

Re: Widget development

Jian,

You will still need to follow my example above (the sparkline6.htm example). You have all the code you need to complete this task in the above examples. The functionality is NOT built into the sparkline tag, it is only built into the javascript widget, so you will have to write javascript to accomplish this task.
Enthusiast

Re: Widget development

Lewis.

we got error as doing following:

final SparklineWidget sparklineWidget = getDoubleSparklineWidget();
final StringBuilder formattedDataString = new StringBuilder();
SparklineWidgetUtils.buildData(formattedDataString, sparklineWidget);
ctx.addViewObject("doubleSparkline", formattedDataString.toString());

ERROR 01 Sep 2009 17:50:44,052 [http-8080-Processor24] [org.apache.catalina.core.ApplicationDispatcher.invoke(723)] Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.el.ELException: Attempt to convert String "[{ minimum: 1251849043244, maximum: 1251852583244, data: [[1251849043244, 0.0],
[1251849103244, 1.0],
[1251849163244, 2.0],
[1251849223244, 3.0],
[1251849283244, 4.0],
[1251849343244, 5.0],
[1251849403244, 6.0],
[1251849463244, 7.0],
[1251849523244, 8.0],
[1251849583244, 9.0],
[1251849643244, 10.0],

...

[1251852583244, 38.0]] }]" to type "com.teradata.tags.widgets.model.SparklineWidget", but there is no PropertyEditor for that type ...
at org.apache.commons.el.Logger.logError(Logger.java:481)
at org.apache.commons.el.Logger.logError(Logger.java:498)
at org.apache.commons.el.Logger.logError(Logger.java:566)
at org.apache.commons.el.Coercions.coerceToObject(Coercions.java:769)
at org.apache.commons.el.Coercions.coerce(Coercions.java:343)
at org.apache.commons.el.ExpressionEvaluatorImpl.convertToExpectedType(ExpressionEvaluatorImpl.java:345)
at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:267)
at org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:929)
at org.apache.jsp.WEB_002dINF.portlet_002djsp.summary_jsp._jspx_meth_vp_005fsparklineWidget_005f0(summary_jsp.java:177)
at org.apache.jsp.WEB_002dINF.portlet_002djsp.summary_jsp._jspx_meth_vp_005ftab_005f0(summary_jsp.java:147)
at org.apache.jsp.WEB_002dINF.portlet_002djsp.summary_jsp._jspx_meth_vp_005ftabs_005f0(summary_jsp.java:106)
at org.apache.jsp.WEB_002dINF.portlet_002djsp.summary_jsp._jspService(summary_jsp.java:67)

Enthusiast

Re: Widget development

Another questoin:

I notice the 13.0.1.1 include sparkline to support two curve by
specify result.setChartType(ChartType.DOUBLE); without this setting. we only get one curve.

How about three curves or more ... ?
Teradata Employee

Re: Widget development

Jian,

Can you please post your .jsp summary code? You are getting a java exception when your .jsp trys to render. My guess is that you are trying to pass the "doubleSparkline" string you have created to the sparkline tag. You can no longer use the sparkline tag with the method outlined above. You must use the widget by writing custom javascript.
Enthusiast

Re: Widget development

<%@ page contentType="text/html" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="vs" uri="http://teradata.com/viewpoint/security" %>
<%@ taglib prefix="vp" uri="http://teradata.com/viewpoint/core"%>






I/O Utilization"
context="${context}_2" model="${doubleSparkline}" width="440" height="70" />




Enthusiast

Re: Widget development

[div class="cpu_daily"]
[vp:tabs id="${context}widgets" context="${context}" hiddenRender="true"]

[vp:tab context="${context}" label="2 Sparklines"]
[vp:sparklineWidget label="CPU Utilization [br][font color= \"#999\"]I/O Utilization[/font]"
context="${context}_2" model="${doubleSparkline}" width="440" height="70" /]
[/vp:tab]

[/vp:tabs]
[/div]
Enthusiast

Re: Widget development

the model name "doubleSparkline" is used only once in public void summary(ControllerContext ctx). and declared in summary.jsp. Lewis, do you email or msn/skype for better communication?
Teradata Employee

Re: Widget development

Jian,

You CANNOT use the <vp:sparklineWidget /> tag with this method. As I walked you through in earlier posts, you need to build a custom javascript controller. The javascript controller that you built off of the "sparkline6" example needs to be passed the data you put into the "doubleSparkline" view object.

I would like to keep communication to forum posts so the community can benefit.
Enthusiast

Re: Widget development

OK, if we can not use < sparklinewidget=""> tag, does that mean sparklineWidget is incapable to do thing like this? could you present a complete example from summary.jsp and function implementation of public void summary(ControllerContext ctx) to make it clear?
Teradata Employee

Re: Widget development

Jian,

Let me preface this post by recommending that you go back and review the technology that you are currently working with. A thorough understanding of the technology is essential for developing for this platform. Please review all of the documentation provided with the PDK as well as the example portlets that are provided. There is a wealth of information in these, and will help you to understand what occurs in the life of a portlet so you can more easily accomplish the task of programming a portlet. With that being said, I will again present you with the same code on how to complete your task. Please understand that it is not my responsibility to provide a line-by-line working example, it is YOUR job to actually write the program because this is YOUR job. I will provide you again with the tools necessary to get the job accomplished.

With that being said, let's walk through this:

First, you will need to retrieve the data you want to display and create a SparklineWidget object from the data. The List myDataList is the list of some model objects that you want to display as data. You will need to get this data from the DAO with which you are interested in seeing data from:

public SparklineWidget getDoubleSparklineWidget(final List<MyDataType>> myDataList)
{
SparklineWidget result = new SparklineWidget();
result.setChartType(ChartType.DOUBLE);

TimeSequenceData[] data = new TimeSequenceData[displayMinutes];
TimeSequenceData[] data2 = new TimeSequenceData[displayMinutes];
int i = 0;
for (final MyDataType model : myDataList)
{
data[i] = new TimeSequenceData(model.getTimestamp1(), model.getValue1(), null);
data2[i] = new TimeSequenceData(model.getTimestamp2(), mode.getValue2(), null);
i++;
}
result.setDataAt(0, data);
result.setDataAt(1, data2);
return result;
}

Next, you need to create a Sparkline widget readable string of data from your SparklineWidget object that is returned by the above function:

public String getDoubleSparklineDataString(final SparklineWidget sparklineWidget)
{
final StringBuilder formattedDataString = new StringBuilder();
SparklineWidgetUtils.buildData(formattedDataString, sparklineWidget);

return formattedDataString.toString();
}

Now you need to pass that data string to your summary page so it can be used by your widget. You will need to add that as a view object:

public void summary(final ControllerContext ctx)
{
final List<MyDataType> myDataList = // some DAO call to get data here;
final SparklineWidget sparklineWidget = getDoubleSparklineWidget(myDataList);
final String myDataString = getDoubleSparklineDataString(sparklineWidget);
ctx.addViewObject("myDataString", myDataString);
}

Now you need to construct a custom sparkline widget that displays the data you have passed in the view as "myDataString". I have pasted virtually all of the code from the sparkline6 example in here and changed a couple of names/lines that I told you to change before:

<div id="${context}mySparkline"></div>

<script type="text/javascript">
TDPortalManager.onPortletLoad({
var sparkline = new SparklineController('${context}mySparkline');
sparkline.setData(${myDataString});
sparkline.init(sparkline.context, 448, 50, "My Title", 0, 0.15, 'line', 0.12, 2);
});

function SparklineController(context)
{
this.context = context;
this.classname = this.context + "_table";
this.id = this.context + "_tbl";
this.data = [];
var ctl = this;
}

SparklineController.prototype.setData = function(data)
{
this.data = data;
}

SparklineController.prototype.init = function(id, width, height, note1, yMin, yMax, type, ref, numDataSets)
{
yMax = 100;
ref = 40;
// Create a new chart instance.
this.chart = new TjsChart(id, width, height);
this.chart.addDataSets(this.data, null, null, null, numDataSets);

/* Create a new sparkline instance that references the chart. */
GlobalReference = new TjsSparkline(this.chart, type, note1, yMax, yMin, ref, 'accordions');
var axis = this.chart.xAxis;
axis.tickCount = 1;
axis.stepSize = 900000;
axis.label.func = myTimestamp;
if (GlobalReference != null)
GlobalReference.render();

GlobalChart = this.chart;
}

function myTimestamp(val)
{
try
{
return new Date(val).format("hm");
}
catch (e)
{
return val;
}
}
</script>

I will conclude this post by stressing again that you have ALL the code/tools you need to complete this task as I simply cut & pasted from above posts and the sparkline6 example code.