Wrap title and sub title to next lines in pie amchart 3 - angular6

I am using pie amchart v3, and i am using allLabels property to display the title and subtitle. But the problem is that, title is not wrapping to the next line as shown below
How to Wrap the text "TOP BUS TYPES: BUS TYPES" to next line?
Below is my code.
const chart = this.AmCharts.makeChart( "mychart", {
"type": "pie",
"theme": "light",
"dataProvider": busvalue,
"titleField": "title",
"valueField": "value",
"labelsEnabled": false,
"radius": "40%",
"innerRadius": "60%",
"colorField": "color",
"allLabels": [{
"y": "48%",
"align": "center",
"size": 17,
"bold": true,
"text": 'TOP BUS TYPES: BUS TYPES',
"color":'#000000'
},{
"y": "52%",
"align": "center",
"size": 12,
"text": ''
"color": '#000000
}],
...
});
}

There isn't any mechanism to automatically wrap free labels (allLabels) in amcharts v3. You have to insert your own newline characters as needed in your string, e.g. "text": 'TOP BUS TYPES:\nBUS TYPES'
AmCharts.makeChart("mychart", {
"type": "pie",
"theme": "light",
"dataProvider": [{
"title": "1",
"value": 10
}, {
"title": "2",
"value": 10
}, {
"title": "3",
"value": 10
}],
"titleField": "title",
"valueField": "value",
"labelsEnabled": false,
"radius": "40%",
"innerRadius": "60%",
"colorField": "color",
"allLabels": [{
"y": "48%",
"align": "center",
"size": 17,
"bold": true,
"text": 'TOP BUS TYPES:\nBUS TYPES',
"color": '#000000'
}, {
"y": "52%",
"align": "center",
"size": 12,
"text": '',
"color": '#000000'
}]
});
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="https://www.amcharts.com/lib/3/pie.js"></script>
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script>
<div id="mychart" style="width: 100%; height: 400px;"></div>

Related

How to filter data using a slider in vega-lite?

I am using the following code to plot a bubble plot using vega-lite. I want to transform values as I change the year value using the slider. But it's not working.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"description": "Drag the sliders to highlight points.",
"data": {
"url": "https://raw.githubusercontent.com/shre2398/InformationVisualization/main/gapminder.tsv",
"format": {
"type": "tsv"
}
},
"title": {
"text": "Gapminder Global Indicators",
"anchor": "middle",
"fontSize": 16,
"fontWeight": 700
},
"config": {
"axis": {
"titleFontSize": 13,
"titleFontWeight": "bold"
}
},
"params": [{
"name": "CurrentYear",
"value": [{"year": 1977}],
"select": {"type": "point", "fields": ["year"]},
"bind": {
"year": {"input": "range", "min": 1952, "max": 2007, "step": 5}
}
},{
"name": "View",
"select": "interval",
"bind": "scales"
}],
"width": 650,
"height": 400,
"mark": {
"type": "circle",
"opacity": 0.8,
"stroke": "white",
"strokeWidth": 1
},
"encoding": {
"x": {
"field": "gdpPercap",
"type": "quantitative",
"axis": {"grid": false},
"scale": {
"type": "log",
"base": 10
}
},
"y": {
"field": "lifeExp",
"type": "quantitative",
"axis": {"title": ""}
},
"size": {
"field": "pop"
},
"color": {
"field": "continent"
}
}
}
If I add the following tranform block, it doesn't work.
"transform":[{"filter": {"param": "CurrentYear"}}]
I have already tried the following link :
https://vega.github.io/vega-lite/examples/interactive_query_widgets.html
It is because you are reading in your year column as strings, and then using a numerical selection to filter. You can see that the year values are strings in the "Data Viewer" tab. Reading in the data like this works with the transform filter you suggested above:
"data": {
"url": "https://raw.githubusercontent.com/shre2398/InformationVisualization/main/gapminder.tsv",
"format": {
"type": "tsv",
"parse": {"year": "number"}
}
}

vega lite - persist null date/time in chart

How do I persist the null in the data on visualization with vega chart while rendering the date/time for data the timestamp. Right now, it looks like null data is getting passed as default time of 04:00
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"data": {
"values": [
{
"x": null,
"y": "recoPU8F3Asuc8t3n"
},
{
"x": "2017-06-02T07:00:00.000Z",
"y": "reco056sZzsAd7qVp"
},
{
"x": null,
"y": "reclQZbw7CiAegm1f"
},
{
"x": "2017-07-14T07:00:00.000Z",
"y": "recAzUhUdekIdkSVt"
},
{
"x": null,
"y": "rec0NHCpaRDP9W1pd"
},
{
"x": null,
"y": "recPYz3QNpXgrmBVy"
}
]
},
"config": {
"range": {
"category": [
"#46bfdd"
]
},
"legend": {
"disable": false,
"labelColor": "#333",
"labelFontSize": 11,
"symbolSize": 30,
"rowPadding": 4,
"symbolType": "circle",
"symbolStrokeWidth": 0,
"titleColor": "#666666",
"titleFontSize": 11,
"titlePadding": 10,
"titleFontWeight": 500,
"orient": "right"
},
"axisY": {
"tickMinStep": 1,
"format": "~s",
"formatType": "number"
},
"axis": {
"domainColor": "#E8E8E8",
"gridColor": "#E8E8E8",
"tickColor": "#E8E8E8",
"grid": true,
"gridWidth": 1,
"labelColor": "#666666",
"labelFontSize": 11,
"labelLimit": 180,
"titleColor": "#999999",
"tickSize": 16,
"titleFontSize": 13,
"titlePadding": 10,
"titleFontWeight": 400,
"labelPadding": 4,
"titleLimit": 180
},
"autosize": {
"type": "fit",
"contains": "padding"
},
"axisLeft": {
"labelFontSize": 11,
"labelColor": "#999999",
"labelLimit": 180,
"titleFontSize": 13,
"titleFontWeight": 400,
"titleLimit": 180
},
"style": {
"label": {
"align": "left",
"baseline": "middle",
"dx": 4
},
"cell": {
"stroke": "transparent"
}
}
},
"mark": {
"type": "bar",
"width": {
"band": 0.7
},
"tooltip": true,
"cornerRadiusEnd": 3,
"cursor": "pointer",
"color": "#4787cd"
},
"params": [
{
"name": "highlight",
"select": {
"type": "point",
"on": "mouseover"
}
},
{
"name": "select",
"select": "point"
}
],
"encoding": {
"x": {
"field": "x",
"type": "nominal",
"axis": {
"labelAngle": -90,
"format": "%I:%M",
"formatType": "time",
"title": "Reservation On"
},
"sort": {
"encoding": "x",
"order": "ascending"
},
"timeUnit": "hoursminutes"
},
"y": {
"field": "y",
"type": "quantitative",
"aggregate": "count",
"axis": {
"title": "Number of records"
}
},
"tooltip": [
{
"field": "x",
"title": "Reservation On",
"format": "%I:%M",
"formatType": "time",
"timeUnit": "hoursminutes"
},
{
"field": "y",
"type": "quantitative",
"aggregate": "count",
"title": "Number of records"
}
],
"fillOpacity": {
"condition": [
{
"param": "select",
"value": 1
}
],
"value": 0.3
},
"strokeWidth": {
"condition": [
{
"param": "select",
"empty": false,
"value": 2
},
{
"param": "highlight",
"empty": false,
"value": 1
}
],
"value": 0
}
},
"transform": [
],
"height": 372,
"width": 536
}
One way to do this is by replacing your "format" with an appropriate "labelExpr":
"axis": {
"labelAngle": -90,
"labelExpr": "isValid(datum.value) ? timeFormat(datum.value, '%I:%M') : 'null'",
"title": "Reservation On"
}

Rotate x-axis label in vega heatmap?

I have built a heat map of correlation matrix
How can I rotate the x-axis label
Is it possible to make the legend vertical like
I tried
"axes": [
{
"orient": "bottom",
"scale": "x",
"labelAngle": -45,
"tickOffset": 0,
"labelAlign": "right",
"domain": false,
"title": "Features"
},
{
"orient": "left",
"scale": "y",
"domain": false,
"title": "Features"
}
],
"legends": [
{
"orient": "right",
"direction" : "vertical",
"fill": "color",
"type": "gradient",
"title": "Correlation",
"titleFontSize": 12,
"titlePadding": 4,
"gradientLength": {"signal": "height - 16"}
}
],
but not happening
i am using vega "https://vega.github.io/schema/vega/v3.json" schema
Rotating the x-axis names, this worked
{
"orient": "bottom",
"scale": "x",
"labelOverlap":false,
"domain": false,
"title": "Features",
"encode": {
"labels": {
"update": {
"angle": {"value": -50},
"fontSize": {"value": 10},
"align": {"value": "right"}
}
}
}
},

Sort the stack segments of barchart

I played with stacked bar charts and wanted to create the Spanish flag with Vega Lite.
I specified the stripes height and color in the data but don't manage to sort the individual stacks:
I set the scale to null, so that the color is taken from the specified field.
I encoded the position of the stripe in the pos attribute, and want to sort the segements by that.
I've also tried to slightly vary the color of the red stripes, but that didn't help.
Spec:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Fun with Flags",
"data": {
"values": [
{"h": 5, "color": "#aa151b", "pos": 6, "country": "spain"},
{"h": 5, "color": "#f1bf00", "pos": 4, "country": "spain"},
{"h": 5, "color": "#aa152b", "pos": 2, "country": "spain"}
]
},
"width": {"step": 300},
"mark": {"type": "bar"},
"encoding": {
"x": {"field": "country", "type": "nominal"},
"y": {"field": "h", "type": "quantitative"},
"color": {
"field": "color",
"scale": null,
"type": "nominal",
"sort": {"field": "pos", "op": "min", "order": "descending"}
}
}
}
Here's a link to the Vega Editor with the Spec.
Instead of sorting the color encoding, I had to specify the order channel, as described in the docs.
This gives me the following spec:
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"description": "Fun with Flags",
"data": {
"values": [
{"h": 5, "color": "#aa152b", "pos": 6, "country": "spain"},
{"h": 5, "color": "#f1bf00", "pos": 4, "country": "spain"},
{"h": 5, "color": "#aa152b", "pos": 2, "country": "spain"}
]
},
"width": {"step": 300},
"mark": {"type": "bar"},
"encoding": {
"x": {"field": "country", "type": "nominal"},
"y": {"field": "h", "type": "quantitative"},
"color": {
"field": "color",
"scale": null,
"type": "nominal"
},
"order": {
"field": "pos",
"type": "quantitative"
}
}
}
And correct Spanish flag:
Link to Vega Editor

Show/hide a KineticJS layer loaded from JSON within Angular

I am trying to hide a layer in KineticJS that is built from a JSON string. The layer won't hide, however. If I try to hide a shape having an ID in the JSON, it does work. Not sure if I have incorrectly created my layer ID in the JSON, or if KineticJS has issues with layer showing/hiding. There is no console error. The layer just won't hide. KineticJS is version v5.1.1. Help?
Here's the relevant JSON....
{
"attrs": {
"width": 524,
"height": 500
},
"className": "Stage",
"children": [
{
"attrs": {},
"className": "Layer",
"id": "layer1",
"children": [
{
"attrs": {
"draggable": true
},
"className": "Group",
"children": [
{
"attrs": {
"id": "firstShape",
"x": 25,
"y": 25,
"radius": 190,
"fill": "green"
},
"className": "Circle"
},
{
"attrs": {
"width": "auto",
"height": "auto",
"x": 64,
"y": 120,
"text": "Some label",
"fontSize": 10,
"fontFamily": "Arial",
"fill": "white"
},
"className": "Text"
}
]
}
]
}
]
}
Here's the event handler which does the layer hide... I find that this is getting called correctly, and the layer just isn't hiding.
scope.$on('hideLayer', function(){
scope.kineticStageObj.get('#layer1').hide();
scope.kineticStageObj.draw();
});
Looks like your json is wrong. id of layer should be inside attrs object.
"attrs": {
"id: : "layer1"
},
Try this:
{
"attrs": {
"width": 524,
"height": 500
},
"className": "Stage",
"children": [
{
"attrs": {
"id": "layer1"
},
"className": "Layer",
"children": [
{
"attrs": {
"draggable": true
},
"className": "Group",
"children": [
{
"attrs": {
"id": "firstShape",
"x": 25,
"y": 25,
"radius": 190,
"fill": "green"
},
"className": "Circle"
},
{
"attrs": {
"width": "auto",
"height": "auto",
"x": 64,
"y": 120,
"text": "Some label",
"fontSize": 10,
"fontFamily": "Arial",
"fill": "white"
},
"className": "Text"
}
]
}
]
}
]
}