Hello All,
I am working with viz frame Stacked bar chart.
Now i need to display time vales on X-Axis.
I need to populate the time values from my JSON Object.But while displaying time values it is displaying as some garbage numbers instead of time.
How can i print the time values on X-Axis.
Below is my Code.
var DataSet = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [{name : "LossType",value : "{lossType}"},
{name : "Machine",value : "{machine}"}],
measures : [
{name : "TimeLoss",value : "{timeFrom}"
},
// {name : "MachineStatus",value : "{crStatus}"},
],
data : {path : "/modelData"}
});
Regards,
Shekar.
Request clarification before answering.
MAntri,
most likely the "garbage numbers" is the javascript time... try new Date(youtTimeObject) -- this will display the datetime object.
the long number you see... most likely is the number of milliseconds since 1/1/1970
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay, so this is a valid Javascript date if you use:
var timeFrom = new Date(myArray[j].DateFrom)
You don't need to call getTime(). You just have to tell your dimension binding that its dataType is "date"
If you are using an XML view it would be:
var timeFrom = new Date(myArray[j].DateFrom)
var hours = timeFrom.getHours();
var minutes = timeFrom.getMinutes();
var seconds = timeFrom.getSeconds();
var timeOnly = hours + ":" + minutes + ":" + seconds
or do some more formatting like adding leading zeroes if a value is <10 or whatever you like.
Hello Pascal,
Still am not getting the time values.
for (var i = 0;i<uniqueLossTypeLegth;i++)
{
for (var j=0;j<dataLength;j++)
{
if (uniqueLossTypes[i] == myArray[j].LossType )
{
losstypeValue = myArray[j].LossType;
machineValue = myArray[j].Machine;
lossCategoryValue = myArray[j].LossCategory;
var timeFrom = myArray[j].DateFrom
timeFrom = new Date(timeFrom);
var hours = timeFrom.getHours();
var minutes = timeFrom.getMinutes();
var seconds = timeFrom.getSeconds();
var timeOnly = hours + ":" + minutes + ":" + seconds
var timeTo = myArray[j].DateTo.split(" ")[1];
var hrmmss = myArray[j].TimeLossDuration.split(":");
//timeLossDuration = parseInt(timeLossDuration) + parseInt(myArray[j].TimeLossDuration);
var hrs = parseInt(hrmmss[0]);
var min = parseInt(hrmmss[1]);
//var sec = parseInt(hrmmss[2]);
var totalTime = (hrs * 60) + min;
timeLossDuration = totalTime + totalTime;
if (myArray[j].Machine == myArray[j].CausalResultant)
{
CRStatus = "C"
}
else
{
CRStatus = "R"
}
}
}
graphArray.push({lossType : losstypeValue,tlDur : timeLossDuration,machine : machineValue,crStatus : CRStatus,timeFrom : timeOnly});
totalLossValue = 0;
}
d3Chart.setVizType("stacked_bar");
//d3Chart.setVizType(" 100_dual_stacked_bar");
//d3Chart.setVizType("stacked_column");
var graphModel = new sap.ui.model.json.JSONModel();
graphModel.setData({modelData: graphArray});
var DataSet = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [{name : "LossType",value : "{lossType}"},
{name : "Machine",value : "{machine}"}],
measures : [
{name : "TimeLoss",value : "{timeFrom}"},
// {name : "MachineStatus",value : "{crStatus}"},
],
data : {path : "/modelData"}
});
Please check this code and let me know if any modifications need to be done
Hi Mantri,
thanks for the jsbin. Unfortunately, I have to say that there are a lot of mistakes in your code.
If you want to display time based columns, you should use the TimeAxis, see:
In your example, matrixModel is not defined. Also your time calculation is wrong, as you are adding "0" to EVERY value. This means, if you got the following values:
hours: 3
minutes: 30
seconds: 00
Your full "timeOnly" will be 30:300:000 which is obviously not a valid time format.
Furthermore you are not using the MVC concept, which is not a "real" mistake, but this makes your code hard to read.
I am sorry but I do not have the time to rewrite your complete code. But you can have a look at the above mentioned example in sapui5 explored. There you can see and download the template of what you need in a correct structure. Its written with an xml view, which I would suggest as the view language anyway.
Greetings
Pascal
Hi Pascal,
Actually i am loading data from JSON File and in hurry am about to do modification for existing code.And those are taht mistakes actually you are seeing.Now please let me know how to modify my code to get Time values on X-Axis
Please see the properties code snippet and suggest the modifications need to be done.
Please let me now which charts do we need to use either SAP Provided or D3 Charts and its advantages and drawbacks
Regards,
Shekar
| User | Count |
|---|---|
| 6 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.