how solve writing back value to backend tableview issue in qml? - qt

In tableview i used a textfield as a delegate component in that i edited a value in second row its shown in red color but after scrolling down same color its showing in 20 row . why ?
check a following code and images
TableView {
id: tableView
clip: true
visible: true
anchors.fill: parent
flickableDirection: Flickable.VerticalFlick
anchors.rightMargin:0
anchors.topMargin: 50
anchors.leftMargin: 5
onWidthChanged: forceLayout()
onHeightChanged: forceLayout()
property var columnWidths: [40,150,150,150]
columnWidthProvider: function (column) { return columnWidths[column] }
rowHeightProvider: function () { return 40 }
columnSpacing: 4
model: TableModel {
TableModelColumn { display: "checked" }
TableModelColumn { display: "fruitType" }
TableModelColumn { display: "fruitName" }
TableModelColumn { display: "fruitPrice" }
rows: [
{
// Each property is one cell/column.
checked: 1,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 2,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 3,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 4,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 5,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 6,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 7,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 8,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 9,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 10,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 11,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 12,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 13,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 14,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 15,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 16,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 17,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 18,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 19,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 20,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 21,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 22,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 23,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 24,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 25,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 26,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 27,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 28,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 29,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 30,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 31,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 32,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 33,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
checked: 34,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
checked: 35,
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
checked: 36,
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
]
}
delegate: DelegateChooser {
DelegateChoice {
column: 0
delegate: Text {
text: model.display
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
DelegateChoice {
delegate: TextField {
id : textss
property bool edited : false
text: model.display
color:edited ?"red" : "#000000"
font.family: "Helvetica"
font.pixelSize: 12
selectByMouse: true
clip: true
background: Rectangle {
color: "lightgray"
border.width: 2
anchors.fill: parent
}
onAccepted: {
model.display = textss.text
edited = true
console.log( model.display)
}
}
}
}
[i edited a value in second row its shown in red color but after scrolling down same its color showing in 20 row ]
(https://i.stack.imgur.com/8MIJD.png)
[check a 20 line ]
(https://i.stack.imgur.com/7R4N3.png)
how to resolve this issue in tableview ? In qt 6.2.4 version

As I said in the comments, you should not save state on delegates:
Delegates are instantiated as needed and may be destroyed at any time. As such, state should never be stored in a delegate.
The usuall way to do this is with another role on the model, which in TableModel case is not feasible, so I advice you to create a C++ QAbstractTableModel.
Having said that here is an ugly example on how to make this work without an aditional role on the model. You should never use this in production.
import QtQuick
import QtQuick.Controls
import Qt.labs.qmlmodels
TableView {
id: tableView
clip: true
visible: true
anchors.fill: parent
flickableDirection: Flickable.VerticalFlick
anchors.rightMargin:0
anchors.topMargin: 50
anchors.leftMargin: 5
onWidthChanged: forceLayout()
onHeightChanged: forceLayout()
property var columnWidths: [40,150,150,150]
columnWidthProvider: function (column) { return columnWidths[column] }
property var data_: [
{
// Each property is one cell/column.
checked: true,
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
{
// Each property is one cell/column.
fruitType: "Apple",
fruitName: "Granny Smith",
fruitPrice: 1.50
},
{
fruitType: "Orange",
fruitName: "Navel",
fruitPrice: 2.50
},
{
fruitType: "Banana",
fruitName: "Cavendish",
fruitPrice: 3.50
},
]
rowHeightProvider: function () { return 40 }
columnSpacing: 4
model: TableModel {
TableModelColumn { display: "checked" }
TableModelColumn { display: "fruitType" }
TableModelColumn { display: "fruitName" }
TableModelColumn { display: "fruitPrice" }
rows: data_
}
delegate: DelegateChooser {
DelegateChoice {
column: 0
delegate: Text {
text: model.index + 1
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
DelegateChoice {
delegate:
Rectangle{
id: rect
color: "lightgray"
border.width: 2
required property var model
TextInput {
id : textss
text: model.display
property bool fooNotify: false
color: "#000000"
font.family: "Helvetica"
font.pixelSize: 12
selectByMouse: true
clip: true
anchors.fill: parent
onTextEdited: {
model.display = textss.text
tableView.data_[rect.model.index] = true
color=Qt.binding(
function() { if (tableView.data_[rect.model.index]){ return "red"} return "black"}
)
console.log( model.display)
}
}
}
}
}
}

Generally, I have found that ListView + ListModel is superior to TableView + TableModel. This is because (1) TableModel is a lab's feature, (2) there are challenges having updates to TableModel seen in TableView, and (3) there are customization issues with TableView. With ListView, you know what you're going to get and it has been around for a lot longer than TableView.
I had a look at your data and found it was really 3 records repeated, and you were not using the checked property as intended, so, I replaced it with the built-in index. I also added support to supply different editing between string vs floating point input.
Also, there were issues with the "write back concept" and your use of editing. Since there is no way to track editing for every cell value unless you declared it in the model itself. Instead, I declared a modified property that applies to the entire row. You can see the moment any cell is modified, it triggers the entire row to be flagged as modified.
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
Page {
ListView {
clip: true
width: 540
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.rightMargin:0
anchors.topMargin: 50
anchors.leftMargin: 5
model: MyListModel { }
delegate: RowLayout {
Label {
Layout.preferredWidth: 40
text: (index+1)
color: modified ? "red" : "black"
}
MyTextField { role: "fruitName" }
MyTextField { role: "fruitType" }
MyFloatField { role: "fruitPrice" }
}
ScrollBar.vertical: ScrollBar { width: 20; policy: ScrollBar.AlwaysOn }
}
}
// MyTextField.qml
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
TextField {
Layout.preferredWidth: 150
property string role: "fruitName"
property string roleType: "string"
text: model[role]
color: modified ? "red" : "black"
onAccepted: {
model[role] = text;
modified = true;
}
}
// MyFloatField.qml
import QtQuick
import QtQuick.Controls
MyTextField {
role: "fruitPrice"
roleType: "float"
property int precision: 2
text: model[role].toFixed(precision)
onAccepted: {
model[role] = parseFloat(text);
modified = true;
}
}
// MyListModel.qml
import QtQuick
import QtQuick.Controls
ListModel {
function appendFruit(fruitType, fruitName, fruitPrice) {
append( { fruitType, fruitName, fruitPrice, modified: false } );
}
Component.onCompleted: {
for (let i = 0; i < 10; i++) {
appendFruit( "Apple", "Granny Smith", 1.50 );
appendFruit( "Orange", "Navel", 2.50 );
appendFruit( "Banana", "Cavendish", 3.50 );
}
}
}
You can Try it Online!

Related

HighCharts: align rotated multiline label

I'm trying to align axis labels in HighCharts
Labels should not be trimed, so ellipsis is not allowed
How it looks now:
How I want it to be:
Code: https://jsfiddle.net/9xw6dL3f/25/
{
"chart": {
"width": 500,
"height": 300,
"type": "column"
},
"title": {
"text": null
},
"xAxis": {
"type": "category",
"labels": {
"rotation": -90,
"style": {
"textOverflow": "none"
}
}
},
"series": [
{
"name": "",
"data": [
{ "name": "Follow me into my theatre of lunacy", "y": -10, "color": "#ABC" },
{ "name": "1", "y": 1, "color": "#000" },
{ "name": "2", "y": 2, "color": "#000" },
{ "name": "3", "y": 3, "color": "#000" },
{ "name": "4", "y": 4, "color": "#000" },
{ "name": "5", "y": 5, "color": "#000" },
]
}
]
}
It is possible to move label depending on it's rows count
Add render function to the chart object
{
"chart": {
...
events: {
render() {
for (let i = 0; i < this.xAxis[0].names.length; i++) {
const label = this.xAxis[0].ticks[i].label;
const rows = (label.element.innerHTML.match(/<\/tspan>/g) || []).length;
label.translate(-8 * rows, 0);
}
}
}
where 8 is half of row size in px
https://jsfiddle.net/kLz1uoga/5/

Vega-Lite: Adding custom legends not based on the field value/auto color/auto shape

I'm looking for a way to output custom legends for multi-field data. Ideally, I'd like to statically color-code all the fields I may have (in total there might be about 20), and output legends per color and arbitrary text, or at least a field name.
In the example below, I'd like a legend to show "blue stroke Series 1 red stroke Series 2".
I'd be happy to show what I have at the moment, but I have tried placing "legend" seemingly everywhere it may fit, and it doesn't do anything.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"x": 1, "y": 10},
{"x": 2, "y": 7},
{"x2": 1, "y2": 11},
{"x2": 2, "y2": 12}
]
},
"encoding": {"x": {"type": "quantitative"},
"y": {"type": "quantitative"}},
"layer": [
{
"layer": [
{
"mark": "line",
"encoding": {
"x": {"field": "x"},
"y": {"field": "y"},
"color": {"value": "blue"}
}
},
{
"mark": "line",
"encoding": {
"x": {"field": "x2"},
"y": {"field": "y2"},
"color": {"value": "red"}
}
}
]
}
]
}
Legends in Vega-Lite are created from encodings, so if you want a legend to be shown you need to construct an appropriate encoding. For layered charts, one way to do this is using a datum encoding for each layer, and then you can construct a custom color scale mapping these encodings to the desired color. For example (open in editor):
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{"x": 1, "y": 10},
{"x": 2, "y": 7},
{"x2": 1, "y2": 11},
{"x2": 2, "y2": 12}
]
},
"encoding": {
"x": {"type": "quantitative"},
"y": {"type": "quantitative"},
"color": {
"type": "nominal",
"scale": {"domain": ["Series1", "Series2"], "range": ["blue", "red"]}
}
},
"layer": [
{
"mark": "line",
"encoding": {
"x": {"field": "x"},
"y": {"field": "y"},
"color": {"datum": "Series1"}
}
},
{
"mark": "line",
"encoding": {
"x": {"field": "x2"},
"y": {"field": "y2"},
"color": {"datum": "Series2"}
}
}
]
}

How to format data to algolia

I'm learning How to use Algolia and I have a few questions.
I have the table FreightDriver, which has a relationship one to many with the table Truck
id: ID!
name: String!
email: String!
phoneNumber: String!
cities: [String!]!
state: String!
country: String!
picture: String
trucks: [Truck] #connection(keyName: "byFreightDriver", fields: ["id"])
Then, the table Truck, which has a relationship one to one with the table FreightDriver, and another table, which is Box one to one as well
id: ID!
freightDriverId: ID!
boxId: ID!
brand: String!
model: String!
yearModel: Int!
// and more fields
freightDriver: FreightDriver #connection(fields: ["freightDriverId"])
box: Box #connection(fields: ["boxId"])
and the table Box:
id: ID!
type: String!
width: Float!
height: Float!
depth: Float!
I want to find trucks based on the state and city of the FreightDrivers, and also (if the user needs it), find based on the type of box and brand or model of a truck (just as an example).
Example find by state and city of a FreightDriver:
{
"data": {
"freightDriversByState": {
"items": [
{
"name": "Andrés Montoya",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Ganadera",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 12,
"height": 12,
"depth": 12
}
},
{
"brand": "chevrolet",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Volcadora",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "hola",
"model": "12",
"yearModel": 12,
"box": {
"type": "Plataforma",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 1
}
},
{
"brand": "dasdas",
"model": "12",
"yearModel": 12231,
"box": {
"type": "Grúa",
"width": 1,
"height": 2,
"depth": 3
}
},
{
"brand": "Tesla",
"model": "Semi",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 4,
"height": 4,
"depth": 2
}
}
]
}
},
{
"name": "Roberto mendez",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": []
}
},
{
"name": "Fletes Jalisco Sa de Cv ",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.5,
"depth": 4.5
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2009,
"box": {
"type": "Seca (abierta)",
"width": 2.3,
"height": 2,
"depth": 4
}
},
{
"brand": "Hiundai",
"model": "H100",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 2.35,
"height": 2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2018,
"box": {
"type": "Seca (cerrada)",
"width": 2.7,
"height": 2.2,
"depth": 3
}
},
{
"brand": "Ford",
"model": "F-450",
"yearModel": 2004,
"box": {
"type": "Seca (abierta)",
"width": 2.5,
"height": 2,
"depth": 3
}
}
]
}
},
{
"name": "Cotransport",
"cities": [
"GUADALAJARA"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "Chevrolet",
"model": "CX-5",
"yearModel": 2019,
"box": {
"type": "Seca (cerrada)",
"width": 4,
"height": 3,
"depth": 4
}
}
]
}
},
{
"name": "Andrés",
"cities": [
"EL LIMÓN",
"MAGDALENA",
"SANTA MARÍA DEL ORO",
"GUADALAJARA",
"ETZATLÁN"
],
"state": "JALISCO",
"country": "MX",
"trucks": {
"items": [
{
"brand": "chevrolet",
"model": "12",
"yearModel": 2020,
"box": {
"type": "Seca (abierta)",
"width": 1,
"height": 2,
"depth": 3
}
}
]
}
}
]
}
}
}
But, if I want to find using the state and city of a freight driver, the type of box and the model or brand of a truck, that's where the problem comes, because I'm using Dynamodb and this one does not have relationships, so, it's a little bit tricky to get the exact data. That's why I'd like to use Algolia, but how do I format the data for Algolia in this case? What do I need to do? thanks!
If someone is interested, here's the answer https://discourse.algolia.com/t/how-to-format-data-to-algolia/10897

Highchart Pie Chart not working properly with series

Sample Code
JsFiddle Example for below code.
Highcharts.chart('container', {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares in January, 2018'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: [
{
"name": "Display",
"y": 0.1,
"value": 5
},
{
"name": "Paid Social",
"y": 0,
"value": 0,
sliced: true,
selected: true
},
{
"name": "Direct",
"y": 14.5,
"value": 559
},
{
"name": "Referral",
"y": 2,
"value": 77
},
{
"name": "Email",
"y": 4,
"value": 152
},
{
"name": "Other",
"y": 0,
"value": 1
},
{
"name": "Organic Search",
"y": 23.4,
"value": 901
},
{
"name": "Meta Search",
"y": 0.2,
"value": 5
},
{
"name": "Organic Social",
"y": 2.4,
"value": 93
},
{
"name": "Directory",
"y": 0.2,
"value": 9
},
{
"name": "Other Advertising",
"y": 0.1,
"value": 3
},
{
"name": "OTA Referral Traffic",
"y": 0.7,
"value": 26
},
{
"name": "Paid Search",
"y": 27.8,
"value": 1068
},
{
"name": "Local",
"y": 24.5,
"value": 941
}]
}]
});
Scenario
I want to display dataLabels for all even y value is zero.
In Above code We have "name": "Display" y=0.1 but still it is not displaying in Pie Chart don't know why. If any one have idea about this problem please let me know.
The dataLabels are hidden due to lack of space and overlapping. As a solution you can set: padding: 0
plotOptions: {
pie: {
...,
dataLabels: {
padding: 0,
...
}
}
}
Live demo: https://jsfiddle.net/BlackLabel/g5s27tyb/
API Reference: https://api.highcharts.com/highcharts/plotOptions.pie.dataLabels.padding

How to query nested array with Cosmos DB

Given the following JSON
{
"Families": [
{ "Name": "Smith",
"Children": [
{ "Name": "Bob",
"Pets": [
{ "Name": "Oscar", "Type": "Cat"},
{ "Name": "Otto", "Type": "Dog"}
]
},
{ "Name": "Brittney",
"Pets": [
{ "Name": "Isolde", "Type": "Dog"},
{ "Name": "Ignatz", "Type": "Turtle"}
]
}
]
},
{ "Name": "Miller",
"Children": [
{ "Name": "Alex",
"Pets": [
{ "Name": "Elvis", "Type": "Horse"}
]
}
]
}
]
}
A) I'd like to create a query that yields the following structure
[
{ "FamilyName": "Smith",
"KidName": "Bob",
"Petname": "Oscar"
},
{ "FamilyName": "Smith",
"KidName": "Bob",
"Petname": "Otto"
},
{ "FamilyName": "Smith",
"KidName": "Brittney",
"Petname": "Isolde"
},
{ "FamilyName": "Smith",
"KidName": "Brittney",
"Petname": "Ignatz"
},
{ "FamilyName": "Miller",
"KidName": "Alex",
"Petname": "Elvis"
}
]
B) I'd like to create a query that yields this slightly different structure
[
{ "FamilyName": "Smith",
"KidName": "Bob",
"Petnames": ["Oscar", Otto"]
},
{ "FamilyName": "Smith",
"KidName": "Brittney",
"Petname": ["Isolde", "Ignatz"]
},
{ "FamilyName": "Miller",
"KidName": "Alex",
"Petname": ["Elvis"]
}
]
Your help is greatly appreciated
Robert
There is actually a really good doc for this here: https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-join and here: https://learn.microsoft.com/en-us/azure/cosmos-db/sql-query-object-array#arrays
For arrays, you want to utilize nested joins, like so:
Given:
{
"id": "so-test",
"Families": [
{
"Name": "Smith",
"Children": [
{
"Name": "Bob",
"Pets": [
{
"Name": "Oscar",
"Type": "Cat"
},
{
"Name": "Otto",
"Type": "Dog"
}
]
},
{
"Name": "Brittney",
"Pets": [
{
"Name": "Isolde",
"Type": "Dog"
},
{
"Name": "Ignatz",
"Type": "Turtle"
}
]
}
]
},
{
"Name": "Miller",
"Children": [
{
"Name": "Alex",
"Pets": [
{
"Name": "Elvis",
"Type": "Horse"
}
]
}
]
}
]
}
You can use this query for A:
SELECT
f.Name as FamilyName,
c.Name as KidName,
p.Name as Petname
FROM d
JOIN f IN d.Families
JOIN c IN f.Children
JOIN p IN c.Pets
WHERE d.id = "so-test"
and you'll get this result:
[
{
"FamilyName": "Smith",
"KidName": "Bob",
"Petname": "Oscar"
},
{
"FamilyName": "Smith",
"KidName": "Bob",
"Petname": "Otto"
},
{
"FamilyName": "Smith",
"KidName": "Brittney",
"Petname": "Isolde"
},
{
"FamilyName": "Smith",
"KidName": "Brittney",
"Petname": "Ignatz"
},
{
"FamilyName": "Miller",
"KidName": "Alex",
"Petname": "Elvis"
}
]
For B), use this query which adds the ARRAY method
SELECT
f.Name as FamilyName,
c.Name as KidName,
ARRAY(SELECT DISTINCT VALUE p.Name from p IN c.Pets) as Petname
FROM d
JOIN f IN d.Families
JOIN c IN f.Children
WHERE d.id = "so-test"
you'll get these results:
[
{
"FamilyName": "Smith",
"KidName": "Bob",
"Petname": [
"Oscar",
"Otto"
]
},
{
"FamilyName": "Smith",
"KidName": "Brittney",
"Petname": [
"Isolde",
"Ignatz"
]
},
{
"FamilyName": "Miller",
"KidName": "Alex",
"Petname": [
"Elvis"
]
}
]

Resources