I’m using amcharts stock chart. When using the following code, my chart loads fine and everything works:
var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"theme": "light",
"dataSets": [{
"title": "Values",
"color": "#b0de09",
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}, {
"fromField": "average",
"toField": "average"
}],
"dataProvider": #Html.Raw(ViewBag.ChartData),
"categoryField": "date"
}],
...
And my controller:
public class ChartController : Controller
{
public IActionResult Index()
{
ViewBag.ChartData = JsonConvert.SerializeObject(GetChartData ());
return View();
}
}
However, when I try to add stock events by adding the following code, two things happen: 1) the chart no longer displays, and 2) the GetChartEvents action in the controller is never called, so obviously never returns any data.
var chart = AmCharts.makeChart("chartdiv", {
"type": "stock",
"theme": "light",
"dataSets": [{
"title": "Values",
"color": "#b0de09",
"fieldMappings": [{
"fromField": "value",
"toField": "value"
}, {
"fromField": "average",
"toField": "average"
}],
"dataProvider": #Html.Raw(ViewBag.ChartData),
"categoryField": "date",
"eventDataLoader": {
"url": #Url.Action("GetChartEvents", "ChartController"),
"format": "json",
"showCurtain": true,
"showErrors": true,
"async": true
}
}],
...
and in the controller
public class ChartController : Controller
{
…
[HttpGet]
public IActionResult GetChartEvents()
{
ChartEvent[] events = new ChartEvent[3];
events[0] = new ChartEvent(new DateTime(2007, 12, 17));
events[1] = new ChartEvent(new DateTime(2008, 10, 27));
events[2] = new ChartEvent(new DateTime(2009, 07, 06));
return Json(events);
}
}
ChartEvent is my own class, but because GetChartEvents is never called, I don’t think the issue is how the returned data is formatted.
In the view, if I replace
"url": #Url.Action("GetChartEvents", "ChartController"),
With
"url": "/Chart/GetChartEvents",
GetChartEvents is still never called, but the chart does display itself. I even tried placing the events in the ViewBag, but that doesn’t work either
"dataProvider": #Html.Raw(ViewBag.ChartData),
"stockEvents": #Html.Raw(ViewBag.ChartEvents)
As a final note (and sanity check!), if I output to the page the contents of #Html.Raw(ViewBag.ChartEvents), I get the following that appears fine:
[{"date":"Date(2007,12,17)","type":"arrowUp","backgroundColor":"#00CC00","graph":"g1","description":" "},
{"date":"Date(2008,10,27)","type":"arrowUp","backgroundColor":"#00CC00","graph":"g1","description":" "},
{"date":"Date(2009,07,06)","type":"arrowUp","backgroundColor":"#00CC00","graph":"g1","description":" "}]
Any help or insight would be much appreciated.
Following their guide here, there are few things that might cause problem.
First, quotes:
"url": '#Url.Action("GetChartEvents", "ChartController")',
Notice single quotes around the URL. Without them your js is just invalid, and that's why the graph does not display.
Second, they use "dataLoader" and not "eventDataLoader" property.
Third, make sure to include dataloader plugin:
<script src="amcharts/plugins/dataloader/dataloader.min.js" type="text/javascript"></script>
Related
In Azure Data Factory, I'm attempting to add params to the body of a copy task (connected to a REST API post request as the source). I'm wanting to use dynamic content to do so, but I'm struggling trying to find the real solution for the proper nomenclature. Here's what I have so far.
copy task
dynamic content
{
"datatable":
{
"start":0,
"length": 10000,
"filters": [
{
"name": "Arrival Dates",
"start": "pipeline().parameters.pDate1",
"end": "pipeline().parameters.pDate2"
}
],
"sort": [
{
"name": "start_date",
"order": "ASC"
}
]
}
}
You'll notice that I've added params for dates. Is this the correct nomenclature for trying to add dynamic content? The autocorrect tried to add the # sign in the beginning of the code block, which will cause the entire thing to error out. I've tried adding it before each parameter, but that isn't actually reading the dynamic values either.
This is not correct. You need to use concat to concatenate the different variables. Something like this :
#concat('{ "datatable": { "start":0, "length": 10000, "filters": [ { "name": "Arrival Dates", "start": "',pipeline().parameters.pDate1,'", "end": "',pipeline().parameters.pDate2,'" } ], "sort": [ { "name": "start_date", "order": "ASC" } ] } }')
This is also documented in the SO question.
I can't access my JSON model which has been defined in the manifest.json.
My JSON data "zCatsTestJ" looks like this:
{
"d": {
"results": [{
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}, {
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}]
}
}
The model seems to be accesible as sJsonDate1 is showing me the data in the console but I can't access a single date. In the end I want to loop over those dates and change the formatting.
var sJsonDate1 = this.getOwnerComponent().getModel("zCatsTestJ");
var sJsonDate2 =this.getOwnerComponent().getModel("zCatsTestJ").getProperty("/d/results/1/workdate");
console.log(sJsonDate1);
console.log(sJsonDate2);
Here is the console output where I can see the complete data.
Console sJsonDate1
But when I try to access one datapoint it says undefined
Console sJsonDate2
I have also instatiated the Model directly in the component and it is working fine. When I compare the model object from getOwnerComponent() and the new one they are nearly the same except for the local one having no aBindings
Model comparison in console
Any help will be highly apreciated. Thanks
Your JSON is invalid, status is missing " and you never close the array. I tried it locally after correcting your JSON and it worked fine on my end.
var json = {
"d": {
"results": [
{
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}, {
"status": "30",
"skostl": "6210",
"catshours": "2.50",
"ktext": "-",
"counter": "000003484040",
"mandt": "101",
"pernr": "00015822",
"usrid": "-",
"workdate": "\/Date(1477267200000)\/",
"raufnr": "6000025",
}]
}
};
var myModel = new JSONModel(json);
this.getView().setModel(myModel, "test");
this.getView().getModel("test").getProperty("/d/results/1/workdate"); "/Date(1477267200000)/"
Here is the solution. Somehow the JsonModel was too big (667 Data Points) and wasn't loaded on the time of calling it. That's why it has worked with only two entries.
myModel.attachRequestCompleted(function() {
var sJsonDate = myModel.getProperty("/d/results/1/workdate");
console.log(sJsonDate);
});
I've been working with datatables and I'm able to load the datatable using getJson with strongly typed classes etc and it works just great. Until I hit one snag.
There are times I want to populate a datatable with data that "I don't know about" but I always know that it will be one row of data - it is simply a json string with dynamic content.
Now with datatables you can simply populate the table with aaData and aaCol by assigning a json string to it but my json string contains a column and data IE:
First_name:bob and so on.
A column - on Datatables would be populated with sTitle:Column1 etc and assigned to aaCol.
Does anyone know of a plug in that parses a json string into aaCol and aaData for use with datatables?
I believe you can solve your problem using this approach:
$(document).ready(function() {
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "scripts/objects.php",
"columns": [
{ "data": "first_name" },
{ "data": "last_name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "start_date" },
{ "data": "salary" }
]
} );
} );
In the example above the dataTables uses a serverSide processing, the ajax return a object like this:
{
"draw": 1,
"recordsTotal": 57,
"recordsFiltered": 57,
"data": [
{
"first_name": "Airi",
"last_name": "Satou",
"position": "Accountant",
"office": "Tokyo",
"start_date": "28th Nov 08",
"salary": "$162,700"
}, ...
You can also set the column name using the "name" property inside the specification of each column.
You can the full example in the following link. If you need more assistance I can make a code on my own later today =)
You can check this JsFiddle to understand how to set the columns names
I am using the Angular ui-calendar, which is an Angular version of the Arshaw FullCalendar. My problem is that the calendar itself requires a "title" field, while I have to use a predefined model for appointments, which does not have such a field. The empty JSON model looks like this:
"Appointment": {
"resourceType": "Appointment",
"identifier": [],
"status": {},
"type": {},
"reason": "",
"priority": {},
"description": "",
"start": "",
"end": "",
"minutesDuration": "",
"slot": [],
"comment": "",
"participant": [{
"type": [],
"actor": [],
"required": [],
"status": []
}] //End of "Appointment"
}
I am trying to transform the "description" field name into a "title" in my calendar options. Currently, without the eventDataTransform, the basic configuration is this:
calendarController.calendarOptions = {
calendar: {
lang: 'bg',
height: 450,
editable: true,
selectable: true,
events: calendarController.searchSet,
dataType: "json",
eventColor: '#30ACFF',
header: {
right: 'month agendaWeek agendaDay today prev,next'
},
timeFormat: 'H(:mm)'
}
};
I've found an example of field name transformation on GitHub gist, however it is not the AngularJS compliant configuration and I am not using ajax calls in my app, I'm using a service to fetch data from the server:
calendarController.searchSet = CalendarService.search({type: 'Appointment'});
Hence, it doesn't work for an Angular app and the Angular Docs for ui-calendar configuration are almost non-existent. So basically, I get an event that shows up in the calendar but has no title. What is the right way to configure event field name transformation if you are using Fullcalendar with Angular and a RESTful service to get data and populate the calendar with the correct field names, without modifying the predefined model for the appointment?
Can someone point out to me what I may be doing wrong here? I have a controller pulling data from a JSON file on my server using the $http service, and passing it through an attribute to a directive. The problem is that even though I only see 4 objects in my JSON looping through it gives me 325. Further more none of the attributes are accessible to me.
My JSON
[{
"name": "Cute Shirt",
"Type": "Shirt",
"Size": "S,M,L,XL",
"Color": "R,G,B",
"SRC": "img/shirt.png"
}
,
{
"name": "Cute Shirt",
"Type": "Shirt",
"Size": "S,M,L,XL",
"Color": "R,G,B",
"SRC": "img/shirt.png"
}
,
{
"name": "Cute Shirt",
"Type": "Shirt",
"Size": "S,M,L,XL",
"Color": "R,G,B",
"SRC": "img/shirt.png"
}
,
{
"name": "Cute Shirt",
"Type": "Shirt",
"Size": "S,M,L,XL",
"Color": "R,G,B",
"SRC": "img/shirt.png"
}
]
My Controller
"use strict";
function itemControl ($http,$scope) {
$http.get('doc/products.json' ).success(function(prodata){$scope.data = prodata;});
}
My Directive
app.directive("showcase", function() {
return {
restrict: "A",
template: '{{stuff.length}}',
scope: {
stuff: "#"
}
};
});
And Finally the HTML
<div ng-controller="itemControl">
<div showcase stuff="{{data}}"></div>
</div>
From the AngularJS documentation:
# or #attr - bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings.
Using the = will help
= or =attr - set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute.
You will want to change your <div showcase stuff="{{data}}"></div> to <div showcase stuff="data"></div>
Change # to =
# means it will interpolate the object to string.