ruby fill data in chart.js - ruby

I'm new in ruby programming and I am sticky
I would like to copy data from mesdata to data in data table.
data = [
{
data: Array.new(4) {},
backgroundColor: [
'#F7464A',
'#46BFBD',
'#FDB45C',
'#32CD32',
],
hoverBackgroundColor: [
'#FF6384',
'#36A2EB',
'#FFCE56',
'#00FF00',
],
},
]
mesdata = [10,20,20,40]

Related

Replace each ID in array of IDs with the data fetched from an API by iterating over the array and calling useQuery hook in each iteration in rtk-query

Layout data format:
{
"header": [
{
"cellId": "header1",
"height": "25vh",
"width": null,
"defaultWidgetHeight": "25vh",
"defaultWidgetWidth": null,
"widgetIds": [
3,
2
]
}
],
"footer": [
{
"cellId": "footer1",
"height": "25vh",
"width": null,
"defaultWidgetHeight": "25vh",
"defaultWidgetWidth": null,
"widgetIds": [
4
]
}
],
"leftSidebar": [
{
"cellId": "leftSidebar1",
"height": "70vh",
"width": {
"xs": 12,
"md": 3
},
"defaultWidgetHeight": "30vh",
"defaultWidgetWidth": null,
"widgetIds": [
5
]
}
],
"rightSidebar": [
{
"cellId": "rightSidebar1",
"height": "70vh",
"width": {
"xs": 12,
"md": 3
},
"defaultWidgetHeight": "30vh",
"defaultWidgetWidth": null,
"widgetIds": [
6
]
}
],
"innerHeader": [],
"innerFooter": [],
"innerLeftSidebar": [],
"innerRightSidebar": [],
"center": [
{
"cellId": "center1",
"height": "70vh",
"width": {
"xs": 12
},
"defaultWidgetHeight": "30vh",
"defaultWidgetWidth": null,
"widgetIds": [
7
]
}
]
}
Child component:
Inside the child component, I am trying to transform the layout data and storing a new tranformed layout data in newLayoutData state variable. I am trying to transform it by replacing each ID inside widgetIds array with the data fetched from an API that uses widgetId as a path parameter using useGetDataQuery hook provided by api slice of RTK-query. The problem is that I cannot call hook inside loops or callbacks.
import React, { useState, useEffect } from 'react';
import { useGetDataQuery } from './features/apiSlice';
const Child2 = ({ layoutData }) => {
const [newLayoutData, setNewLayoutData] = useState(null);
useEffect(() => {
const updatedLayoutData = {};
Object.keys(layoutData).forEach((masterContainerId) => {
updatedLayoutData[masterContainerId] = [];
layoutData[masterContainerId].forEach(async(childContainer) => {
updatedLayoutData[masterContainerId].push({
...childContainer,
widgetIds: childContainer.widgetIds.map(async(widgetId) => {
const widgetQuery = useGetDataQuery(`/app/v2/dashboard/widget/${widgetId}`)
return widgetQuery.data;
})
})
});
});
setNewLayoutData(updatedLayoutData);
}, []);
return (
<h1>Layout data transformed</h1>
);
};
export default Child2;
I tried solving this issue using axios but in that case I cannot have the priveledge of using cache that RTK query provides because if the same widgetId appears in some other widgetIds array then axios will again going to make an API call for that ID whereas rtk-query won't and will return the existing cache data for that widgetId.

How to set polygon fill based on imported parameters from postGIS

Have successfully imported polygons in OpenLayers along with popup of pertinent data. Need guidance on assigning fill colors from parameters passed via ajax.
your textHoping to assign fill color based on setting parameter in json file. Currently using:
var polyStyle = new ol.style.Style({
fill: new ol.style.Fill({
color: [12,240,60]
}),
stroke: new ol.style.Stroke({
color: [0,0,0], width: 1
})
});
to load the following:
const layer = new ol.layer.Vector({
source: new ol.source.Vector({
features:features,
projection: 'EPSG: 3857'
}),
style: polyStyle
});
I next tried the following as a test based on the "settings feature the file:
// Polygons style
var setfcolor = function(features) {
console.log(features);
var fcolor;
if (feature.get("setting")=='Carbonate'){
fcolor = "blue";
} else if (feature.get("setting")=='Clastic: continental'){
fcolor = "yellow";
} else if (feature.get("setting")=='Extrusive: mafic'){
fcolor = "brown";
}
};
But it fails and reverts to all black.
Snippet of json file is:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-45.499757432,
60.988125868
],
[
-45.49967049,
60.988157751
],
[
-45.497458466,
60.989470026
],
[
-45.487258845,
60.995518876
],
[
-45.483858593,
60.999870372
],
[
-45.483858591,
60.99987019
],
[
-45.465241806,
60.991366687
],
[
-45.450273556,
60.988997409
],
[
-45.422944921,
60.990687369
],
[
-45.42294477,
60.990687194
],
[
-45.419225021,
60.984549241
],
[
-45.412472331,
60.973399399
],
[
-45.502278621,
60.96070259
],
[
-45.525166866,
60.957726342
],
[
-45.544395412,
60.955624111
],
[
-45.572353843,
60.951692596
],
[
-45.655768925,
60.94244974
],
[
-45.670854236,
60.94123391
],
[
-45.693899808,
60.940200373
],
[
-45.664305174,
60.947778021
],
[
-45.659448977,
60.949020163
],
[
-45.648191047,
60.951923402
],
[
-45.636669092,
60.954825483
],
[
-45.565410441,
60.967827923
],
[
-45.523123774,
60.979977384
],
[
-45.517219284,
60.981999
],
[
-45.517218946,
60.981999115
],
[
-45.5059008,
60.985872696
],
[
-45.499757432,
60.988125868
]
]
]
},
"properties": {
"setting_ty": "Supracrustal",
"setting": "Sedimentary and/or volcanic: undivided",
"lithology": "Basalt, sandstone, conglomerate",
"colour_cmy": "20 40 70 0",
"colour": "247"
}
},
[Polygons and popups working](https://i.stack.imgur.com/TqbV8.jpg)
strong text Got a good lead from Mike user:10118270 and applied it.Replaced the following code
var polyStyle = new ol.style.Style({
fill: new ol.style.Fill({
color: [12,202,50]
}),
stroke: new ol.style.Stroke({
color: [0,0,0], width: 1
})
});
with the following code:
// Polygons style
const fillColors = {
'Slope and deep water': [100,100,100,1],
'Intrusive: syenitic': [240,10,10,1],
'Intrusive: gabbroic': [240,10,10,1],
'Intrusive: anorthositic': [240,10,10,1],
'Intrusive: tonalitic-granodioritic': [240,10,10,1],
'Intrusive: granitic':[240,10,10,1],
'Intrusive: undivided': [230,10,10,1],
'Sedimentary: undivided': [250,250,10,1],
'Clastic: shallow marine': [240,240,20,1],
'Clastic: continental': [255,255,1,1],
'Clastic: deltaic and nearshore': [240,240,20,1],
'Marine sedimentary: undivided': [230,230,10,1],
'Extrusive: mafic': [250,200,10,1],
'Sedimentary and/or volcanic: undivided': [250,120,10,1],
'Carbonate': [10,40,255,1],
'Metamorphic: undivided': [230,10,240,1],
'ice': [250,250,250,1],
};
const style = new ol.style.Style({
fill: new ol.style.Fill(),
stroke: new ol.style.Stroke({
color: [0, 0, 0, 1],
width: 0.5,
}),
});
strong text The end result is shown on the image.
geologic polygon

Apexcharts - bars are too small

I am using a timeline chart from Apexcharts 3.19.0 and I noticed that every time I add a new vertical "category" the bars start to shrink. Is it possible to set the bar height a fixed size?
I am building a timeline chart that represents a production line. Bars are the production and the categories are the machines. And one build is related only to one machine.
This is the series that I pass and if I continue to add new machines bars continue to shrink.
I noticed that Apexcharts makes every bar with such height that every row can take all bars, but I don't need this in my case.
[
{
"name": "B-2004281001-6763",
"data": [
{
"x": "Cube 3-1",
"y": [
1588068083109,
1588071676403
],
}
]
},
{
"name": "B-2004281000-8133",
"data": [
{
"x": "BiZon Prusa i3 Steel-2",
"y": [
1588068021615,
1588075213496
],
}
]
},
{
"name": "B-2004281001-9110",
"data": [
{
"x": "BiZon Prusa i3 Steel-2",
"y": [
1588068068356,
1588078856311
],
}
]
}
]
That's how my chart looks like
My Chart
I had a similar issue and I got around it by using a common shared "x" value ("Production" in your example) and setting "name" values in the series data arrays that were then displayed by dataLabels.
So your modified data:
[
{
name: "B-2004281001-6763",
data: [{ name: "Cube 3-1", x: "Production", y: [ 1588068083109, 1588071676403 ] }]
},
{
name: "B-2004281000-8133",
data: [{ name: "BiZon Prusa i3 Steel-2", x: "Production", y: [1588068021615, 1588075213496 ] }]
},
{
name: "B-2004281001-9110",
data: [{ name: "BiZon Prusa i3 Steel-2", x: "Production", y: [1588068068356, 1588078856311 ], } ]
}
]
and the corresponding dataLabels option (black text color for visibility)
dataLabels: {
enabled: true,
formatter: function(val, opts) {
return opts.w.config.series[opts.seriesIndex].data[opts.dataPointIndex].name;
},
style: {
colors: ["#000000"]
}
}
Check it out here

How to solve "Trying to get property 'name' of non-object" error in laravel Data Tables?

I am using data tables in laravel here I am trying to fetch data with relationships some times relationship id is not present so it gives null value in laravel blade I can handle it by checking if it is null. but in the data table, I can't use it.
returning values to data table
return [
'delivery_run_id' => $run_sheet->delivery_runs->name:
];
when i put before return statement then it work fine but i think that approach is not good
if(empty($run_sheet->delivery_runs->name))
{
$delivery_run = '';
}
else
{
$delivery_run = $run_sheet->delivery_runs->name;
}
I try to set default value for data table column but its not working
var table = $(tablename).DataTable({
responsive: true,
"order": [],
'aoColumnDefs': [{
'bSortable': false,
'aTargets': ['nosort']
}],
buttons: [
'print',
'copyHtml5',
'excelHtml5',
'csvHtml5',
'pdfHtml5',
],
processing: true,
serverSide: true,
ajax: {
url: url,
type: 'get',
data: filters
},
columns: columns,
"language": {
processing: "<img src='https://thumbs.gfycat.com/WatchfulSnarlingBettong-max-1mb.gif'>"
},
"columnDefs": [
{
"data": null,
"defaultContent": "<button>Edit</button>",
"targets": -1
}
]
});
use a ternary operator to check is set or not.
$delivery_run = $run_sheet->delivery_runs->name ?? "";
return [
'delivery_run_id' => $run_sheet->delivery_runs->name ?? "";
];

Add action buttons in vue.js frontend when using server side dataTables

How to add action buttons in frontend vue.js when using server side dataTables?
here is what i have so far, this code is working, but action buttons not give the request when clicking. (the alert is not also firing). the action buttons are showing and calling to editTaxGroup()
$(document).ready(function() {
let tax = 1;
self.dataTable = $("#tax_groups2").DataTable({
serverSide: true,
ajax: {
"columns": [
{ "data": "tax_group_name" },
{ "data": "country.country_name" },
{ "data": "tax_rate_percentage" },
{ "data": "Edit" },
{ "data": "Delete" }
],
data: {
"token": localStorage.getItem("token"),
},
url: 'api/v1/get-tax-groups',
dataFilter: function(data){
var json = jQuery.parseJSON( data );
json.recordsTotal = 100;
json.recordsFiltered = 100;
self.tax_groups = data.data;
return JSON.stringify( json ); // return JSON string
}
},
columns: [
{data: "tax_group_name"},
{data: "country.country_name",},
{data: "tax_rate_percentage"},
{data: "Edit"},
{data: "Delete"},
],
"columnDefs": [
{
"targets": [ -2 ],
"data":"id",
"defaultContent" : '<i class="fas fa-pen"></i>'
},
{
"targets": [ -1 ],
"data":"id",
"defaultContent" : '</i>'
}
],
});
})
$('#tax_groups2 tbody ').on('click', '#edit', function () {
for (let key in self.tax_groups){
alert(1)
console.log(key);
if(self.tax_groups.hasOwnProperty(key)){
console.log(`${self.tax_groups[key]}`)
}
}
} );
});
},
This isn't using Vue at all. You could actually more efficiently use Vue to generate these tables dynamically and set buttons as well. You may want to remove the Vue tag or re-ask the question.

Resources