I have a Highcharts Gantt chart which is pulling parsed JSON data from a MySQL table.
The data spans 4 years, but I need to filter it so that it only shows data for 2022.
The issue is that I cannot use the standard Highcharts data filter as it does not remove empty rows without any data.
I would like to filter the data before the chart is even rendered so that rows without bars are not shown at all. Is that possible?
It is really easy, you just need to filter your JSON data before creating a chart. A simplified process will be like below:
const receivedData = [{
name: 'Start prototype',
start: '2021-04-11',
end: '2021-04-17'
}, {
name: 'Test prototype',
start: '2022-04-11',
end: '2022-04-17'
}, {
name: 'Develop',
start: '2022-06-11',
end: '2022-07-11'
}, {
name: 'Run acceptance tests',
start: '2022-09-11',
end: '2022-09-21'
}];
const filteredData = receivedData.filter(
dataEl => new Date(dataEl.start) > new Date('2022')
);
// THE CHART
Highcharts.ganttChart('container', {
series: [{
name: 'Project 1',
data: filteredData.map(({
name,
start,
end
}) => ({
name,
start: new Date(start).getTime(),
end: new Date(end).getTime()
}))
}]
});
Live demo: https://jsfiddle.net/BlackLabel/0vhdg5jw/
Related
I just installed angular 4 multiselect dropdown to show the data that i am getting from JSON script using services. I am getting the data in my property but now i want to show it in a multiselect dropdown so that i can use multiple values and assign them to my next property. So in the below code i am calling a method of getSubject and it is returning me the data in this.subject property.
this._curriculumService.getSubject(this.appSession.tenant.tenancyName)
.finally(() => {this.saving = false;})
.subscribe((result: listResultDtoOfSubjectDto) => {
this.subjects = result.items;
this.id = this.subjects.map(a => a.code);
this.itemName = this.subjects.map(a => a.name);
})
Now i want to show this data inside inside angular 4 dropdown multiselect and here is a code for that in my component.ts file. The problem is that the dropdown asked for a specific id and name of the property and only then it will be able to show the data in dropdown but in my case i have a name and code returning in this.subjects. So how can i show my data in this dropdown
optionsModel: number[];
myOptions: IMultiSelectOption[];
this.myOptions = [
{ id: 1, name: 'Physics' },
{ id: 2, name: 'English' },
{ id: 3, name: 'English' },
{ id: 4, name: 'Programming'}
];
HTML Code
<div class="form-line focused">
<div class="col-sm-4">
<div class="form-group form-float">
<div class="form-line focused">
<ss-multiselect-dropdown
[options]="myOptions"
[(ngModel)]="optionsModel"
(ngModelChange)="onChange($event)">
</ss-multiselect-dropdown>
</div>
</div>
</div>
</div>
So for that don't declare type of your myOptions as IMultiSelectOption[], instead keep it any or whatever you're receiving from service. As this plugin requires each options to have the id thus, you can add that property to myOptions objects after it's received from service response. So, make sure that property should be unique valued (e.g. subject code).
Let this.subjects is an array of objects you got from service:
optionsModel: number[];
subjects: any;
this.subjects = [
{ code: 11, name: 'Physics' },
{ code: 12, name: 'English' },
{ code: 13, name: 'English' },
{ code: 14, name: 'Programming'}
];
this.subjects.forEach(function(e) { e.id = e.code });
The last line will add id property to each object with value same to subject code. Now the dropdown will work as expected.
Demo Example
I know that this is a simple question, but I got stuck looking for a solution.
First, I got the FormPanel, that obtains data passed by JSON that looks like:
var formPanel = new Ext.FormPanel({
....
[
{name: 'country', mapping: 'country'}
]
...
Then, I populate the store with data from an external file that has a list of countries
var countryStore = new Ext.data.SimpleStore({
fields: ['vcountry', 'vcountrydesc'],
data : Ext.ms.data.countries,
id:1,
});
What I want to do is to set a default value in a Ext.form.ComboBox, which is defined as name: 'country', precisely, I want to do something like this:
var countryFld = new Ext.form.ComboBox({
store: countryStore,
.....
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select Country',
value: 'country', **<---I WANT TO DO THIS, BUT TO DISPLAY A VALUE, NOT A STRING!**
....
}
});
I assume that solution is very simple, but I got stuck on it.
SIMPLE, very stupid of me to ask...
Solution is just like for any other form
dataIndex: 'country',
instead of
value:'country',
I'm using ExtJS 4.2 and I have some records in a MySql database. My question is: How can I create a grid that displays the records in the database?
I tried using ResultSet in a servlet to retrieve the records from the database, but I'm not sure how to proceed from there.
How can i populate the fields in the grid with the records in my database?
I'm new to ExtJS and I'm finding it difficult to come up with a solution for this. Does this have something to do with the store field? If so, how do i go about achieving the above said requirement?
You need to create store, bind to the grid and then load data from server. And sure you need backend for this ExtJS4 do not provide any tools for working with databases
For example( taken from sencha docs ):
Ext.onReady(function(){
Ext.define('Book',{
extend: 'Ext.data.Model',
proxy: {
type: 'ajax',
reader: 'xml'
},
fields: [
// set up the fields mapping into the xml doc
// The first needs mapping, the others are very basic
{name: 'Author', mapping: '#author.name'},
'Title', 'Manufacturer', 'ProductGroup'
]
});
// create the Data Store
var store = Ext.create('Ext.data.Store', {
model: 'Book',
autoLoad: true,
proxy: {
// load using HTTP
type: 'ajax',
url: 'sheldon.xml',
// the return will be XML, so lets set up a reader
reader: {
type: 'xml',
// records will have an "Item" tag
record: 'Item',
idProperty: 'ASIN',
totalRecords: '#total'
}
}
});
// create the grid
Ext.create('Ext.grid.Panel', {
store: store,
columns: [
{text: "Author", flex: 1, dataIndex: 'Author'},
{text: "Title", width: 180, dataIndex: 'Title'},
{text: "Manufacturer", width: 115, dataIndex: 'Manufacturer'},
{text: "Product Group", width: 100, dataIndex: 'ProductGroup'}
],
renderTo:'example-grid',
width: 540,
height: 200
});
});
The main idea is - models are for defining structure of the record and validation(read about it here), stores - for storing and fetching(by parsing response from server or local defined data) records that match model structure(Basic store) and finally grid handles some events(like "load" or "refresh") and updating rows based on grids column defenition(docs)
Below you will find an Ext.form.Panel that has two fields. I chose two random fields in my model that have data. They are not rendering in the form. Note that I am not using MVC in the Extjs framework in this code. How can I get these fields to render? I've pasted the relevant output from the store.data.toSource() to show that I do in fact have data in my store, and only a single record. To view the image with a little larger resolution, right click it and view in another tab.
NOTE: .toSource() only works in Mozilla Firefox
I've tried executing this after creating the form, but it didn't work:
taskForm.getForm().loadRecord(store.getAt(0));
Code:
var taskForm = Ext.create('Ext.form.Panel', {
title: 'Task',
id: 'form1',
width: 600,
height: 200,
bodyPadding: 10,
renderTo: 'TaskEditForm',
store: store,
style: {
'position': 'fixed',
'top': '100px',
'left': '10px'
},
items: [{
xtype: 'label',
labelAlign: 'right',
name: 'project_id',
fieldLabel: 'Project ID',
width: 100
}, {
xtype: 'label',
labelAlign: 'right',
name: 'user_responsible',
fieldLabel: 'User',
width: 100
}],
buttons: [{
text: 'Save Task Detail',
handler: function (btn) {
alert(store.data.toSource());
}
}]
});
========
Edit: #Evan
This code gives the error below:
taskForm.getForm().loadRecord(store.getAt(0));
Error:
TypeError: record is undefined
...
return this.setValues(record.data); // ext-all-debug.js (line 109529)
Line 109529:
loadRecord: function(record) {
this._record = record;
return this.setValues(record.data);
},
Have you read the documentation? store.data is a MixedCollection that holds a bunch of records. The documentation for the load method says:
A class which handles loading of data from a server into the Fields of
an Ext.form.Basic.
You can't just throw in random parameters and expect stuff to work.
What you probably want is:
form.getForm().loadRecord(store.getAt(0)); // Load the first store record into the form
I am trying to load some JSON, in which I store a lot of variables about some 100 anaesthetic drugs for pediatric patients.
The actual values get calculated before from patient's weight, age etc.:
Example:
var propofolInductionTitle = propofolName + ' ' + propofol0PercentConcentration + '- Induktion';
var propofol0InductionDosageMG = (Math.round(kg * 2 * 10) / 10) + ' - ' + (Math.round(kg * 5 * 10) / 10);
I then create my drug as a block of json consisting of the variables I need which are later to be replaced by the calculated values. I specifically try to avoid Strings in the JSON to allow for easier localization to english and french when all variables are defined in the math block.
var hypnotikaJSON = {
"thiopentalTitle": [
{"thiopentalBrandName": ""},
{"vialContentTitle": "thiopentalVialContent"},
{"solutionTitle": "thiopentalSolution"},
{"concentrationTitle": "thiopentalConcentration"},
{"dosageString": "thiopentalDosageString"},
{"atWeight": "thiopentalDosageMG"},
{"thiopentalAtConcentration": "thiopentalDosageML"}
],
"propofolInductionTitle": [
{"propofolInductionBrandName": ""},
{"propofolVialContentTitle": "propofolInductionVialContent"},
{"propofolSolutionTitle": "propofolSolution"},
{"propofolConcentrationTitle": "propofolInductionConcentration"},
{"propofolInductionDosageStringTitle": "propofolInductionDosageString"},
{"atWeight": "propofolInductionDosageMG"},
{"propofolAtInductionConcentration": "propofolInductionDosageML"}
],
"propofolSedationTitle": [
{"propofolSedationBrandName":""},
{"propofolVialContentTitle":"propofolSedationVialContent"},
{"propofolSolutionTitle":"propofolSolution"},
{"propofolConcentrationTitle":"propofolSedationConcentration"},
{"propofolSedationDosageStringTitle":"propofolSedationDosageString"},
{"atWeight":"propofolSedationDosageMG"},
{"propofolAtSedationConcentration":"propofolSedationDosageML"}
],
"laryngealMaskTitle": [
{"laryngealMaskSizeTitle":"laryngealMaskSize"},
{"laryngealMaskCuffSizeTitle":"laryngealMaskCuffSize"},
{"laryngealMaskBiggestETTTitle":"laryngealMaskBiggestETT"},
{"laryngealMaskBronchoscopeSizeTitle":"laryngealMaskBronchoscopeSize"}
]
};
My specific need is that the JSON reader has to give me the key AND value of each object as I need both to populate a template. The reason ist that the fields for the drugs are different in parts. Some have additional routes of administration so I have another key:value pair a different drug doesnt have. Some are given both as bolus and per drip, some arent. So no convenient json structure ist possible.
I found an answer by rdougan here that partly allowed me to do just that:
Model:
Ext.define('my.model.Drug', {
extend: 'Ext.data.Model',
config: {
fields: ['name', 'value']
}
});
Custom Json Reader:
Ext.define('Ext.data.reader.Custom', {
extend: 'Ext.data.reader.Json',
alias: 'reader.custom',
getRoot: function (data) {
if (this.rootAccessor) {
data = this.rootAccessor.call(this, data);
}
var values = [],
name;
for (name in data) {
values.push({
name: name,
value: data[name]
});
}
return values;
}
});
Store:
var store = Ext.create('Ext.data.Store', {
fields: ['name', 'value'],
data: hypnotikaJSON,
autoLoad: true,
proxy: {
type: 'memory',
reader: {
type: 'custom'
}
}
});
Panel:
this.viewport = new Ext.Panel({
fullscreen: true,
layout: 'fit',
items: [{
xtype: 'list',
itemTpl: '<p class="description">{name}</p><p class ="values">{value}</p>',
store: store
}]
});
Unfortunately I'm a physician and no programmer, and after a lot of reading I cant find out to apply this to a nested JSON. The custom reader seems to only go for the first level.
I could do it without a reader, without a store with just a lot of plan html around each entry, that has proven to be very very slow though so I would like to avoid it while updating from Sencha Touch 1.1. and better do it right this time.
Could you please point me to a way to parse this ugly data structure?
Thank you
I don't know much about extending JSON readers, so just guessing, but maybe you are supposed override the 'read' method? Then you can go over the JSON as you wish
Also, if you have control over the JSON you should consider changing it.
Usually, the keys in JSON should be the same throughout all items in the array.
keys are not data, they are metadata.
So, if you do have different properties between different drugs, then something like this might be a solution:
[{
name: 'Propofol 1%',
properties: [
{title: 'induction', value: '22-56g'},
{title: 'Sedation', value: '22'},
etc.
]},
{name: 'nextDrug'}
etc..