I need the text in this graph to stay center wrapped but it goes horizontal instead. Had anyone had this issue with chartjs?
Picture of the graph
It works if you used a set amount of letters such as 'dummy'.
datasets: {
labels: ["Dummy text 1", "Dummy text 2", "Dummy text 3"],
datasets: [
{
label: "",
data: [13, 11, 2],
backgroundColor: [
"rgba(0, 135, 136)",
"rgba(0, 193, 189)",
"rgba(255, 9, 49)"
],
borderColor: [
"rgba(0, 135, 136)",
"rgba(0, 193, 189)",
"rgba(255, 9, 49)"
],
borderWidth: 1
}
]
Fixed this easily with a multi-array and changing the xaxes. Here's the example fix -
labels: [
["Dummy", "Data 1"],
["Dummy", "Data 2"],
["Dummy", "Data 3"]
],
xAxes: [
{
ticks: {
maxRotation: 0,
minRotation: 0
},
}
]
Hopefully this helps someone out :)
scales: {
xAxes: [
{
ticks: {
callback: function (label, index, labels) {
if (/\s/.test(label)) {
return label.split(' ');
} else {
return label;
}
}
}
}
]
This callback function will split your X Axis labels on the basis of space and arrange all the words in a wrapped manner. You can use the same function for Y axis values as well
Related
I am learning MongoDB (5.6) and have a collection with documents like this:
[
{
"_id": {
"$oid": "62642b53df03395a48eba4d3"
},
"title": "Chemical Biology",
"authors": [
"625861411edf9d62ec72c889"
],
"year": 1947,
"sentences": [
"sentence 001",
"sentence 002"
]
}
]
I want to update the array "sentences" to an array of objects (in all the documents of the collection) using the existing value. I expect it like this:
[
{
"_id": {
"$oid": "62642b53df03395a48eba4d3"
},
"title": "Chemical Biology",
"authors": [
"625861411edf9d62ec72c889"
],
"year": 1947,
"sentences": [
{
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50,
"value": "sentence 001"
},
{
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50,
"value": "sentence 002"
}
],
}
]
So far this query is the nearest thing I have achieved:
db.collection.update({},
[
{
"$set": {
"sentences": {
"value": {"$arrayElemAt": ["$sentences", 0]},
//"value": "$sentences",
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50
}
}
}
],
{
multi: true
})
Which of course is producing nearly what I want, but not exactly (since I hard quoted the index to 0). If I could gain access to the current index/value of the array sentences in each loop, I can get the desired result.
[
{
"_id": ObjectId("62642b53df03395a48eba4d3"),
"authors": [
"625861411edf9d62ec72c889"
],
"sentences": [
{
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50,
"value": "sentence 001",
},
{
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50,
"value": "sentence 001"
}
],
"title": "Chemical Biology",
"year": 1947
}
]
Mongo Playground
How can I access the exact numeric array index or element/content in each loop?
Thanks for your patience to read this far. Can you please advice how to use the current/existing value of a numerical array field and convert the same field to an object array using the current value?
Thanks in advance.
As you are working update with aggregation pipeline, you can use $map to iterate elements in sentences and return new sentences array.
db.collection.update({},
[
{
"$set": {
"sentences": {
$map: {
input: "$sentences",
in: {
"order_chem": 50,
"order_bio": 50,
"order_science": 50,
"order_school": 50,
value: "$$this"
}
}
}
}
}
],
{
multi: true
})
Sample Mongo Playground
I am using react-d3-graph for rendering DAG thats hierarchical / layered.
e.g.
Layer-1 [ n1]
Layer-2 [ n11, n21 ]
Layer-3 [ n111, n112][n121,122]
.... and so on.
While I am able to get force graph using sample examples provided (see below), I don't see an option to provide layering or hierarchy like DAG onto graph. What can be done in this case?
React Code:
import React from "react";
import { Graph } from "react-d3-graph";
import { data } from "./sampleGraphData";
import './App.css';
function App() {
const myConfig = {
"automaticRearrangeAfterDropNode": true,
"collapsible": true,
"directed": true,
"focusAnimationDuration": 0.75,
"focusZoom": 1,
"freezeAllDragEvents": false,
"height": 800,
"width": 600,
"highlightDegree": 2,
"highlightOpacity": 0.2,
"linkHighlightBehavior": true,
"maxZoom": 12,
"minZoom": 0.05,
"nodeHighlightBehavior": true,
"panAndZoom": false,
"staticGraph": false,
"staticGraphWithDragAndDrop": false,
"d3": {
"alphaTarget": 0.05,
"gravity": -250,
"linkLength": 120,
"linkStrength": 2,
"disableLinkForce": false
},
"node": {
// "color": "#d3d3d3",
color: "lightgreen",
"fontColor": "black",
"fontSize": 10,
"fontWeight": "normal",
"highlightColor": "red",
"highlightFontSize": 14,
"highlightFontWeight": "bold",
"highlightStrokeColor": "red",
"highlightStrokeWidth": 1.5,
"mouseCursor": "crosshair",
"opacity": 0.9,
"renderLabel": true,
"size": 200,
"strokeColor": "none",
"strokeWidth": 1.5,
"svg": "",
"symbolType": "circle"
},
"link": {
"color": "lightgray",
"fontColor": "black",
"fontSize": 8,
"fontWeight": "normal",
"highlightColor": "red",
"highlightFontSize": 8,
"highlightFontWeight": "normal",
"labelProperty": "label",
"mouseCursor": "pointer",
"opacity": 1,
"renderLabel": false,
"semanticStrokeWidth": true,
"strokeWidth": 3,
"markerHeight": 6,
"markerWidth": 6,
"strokeDasharray": 0,
"strokeDashoffset": 0,
"strokeLinecap": "butt"
}
}
return (
<div id="app">
<h1 className="header">
<span className="title">[DAG example]</span>
</h1>
<Graph
id="graph-id"
// data={d3graph}
data={data}
config={myConfig}
/>
</div>
);
}
export default App;
Resulting graph:
Desired Graph:
I would like to plot a graph in AngularJS, using Highcharts, to be something like this:
This graph represents the load of a server in the last hour. So the datapoints given, contains a point and epoch time.
The data is received in a JSON format, [point,epochtime], as follows:
[
{
"ds_name": "a0",
"cluster_name": "",
"graph_type": "stack",
"host_name": "",
"metric_name": "1-min",
"color": "#BBBBBB",
"datapoints": [
[
0.58,
1604244900
],
[
0.59733333333,
1604244915
],
[
0.6,
1604244930
],
[
0.6,
1604244945
],
[
0.6,
1604244960
],
[
0.6,
1604244975
],
[
0.612,
1604244990
]
]
},
{
"ds_name": "a2",
"cluster_name": "",
"graph_type": "line",
"host_name": "",
"metric_name": "CPUs ",
"color": "#FF0000",
"datapoints": [
[
2,
1604244900
],
[
2,
1604244915
],
[
2,
1604244930
],
[
2,
1604244945
],
[
2,
1604244960
],
[
2,
1604244975
],
[
2,
1604244990
],
[
2,
1604245005
]
]
},
{
"ds_name": "a3",
"cluster_name": "",
"graph_type": "line",
"host_name": "",
"metric_name": "Procs",
"color": "#2030F4",
"datapoints": [
[
1,
1604244900
],
[
1,
1604244915
],
[
1,
1604244930
]
]
}
]
I posted here only part of the dataset, since it is too long, but I think you can understand the format.
How can I draw something similar using Highcharts?
The most important thing here is to properly parse the date. Since the names in the JSON are not the same as Highcharts requires you have to pass them manually to the right places as I did it in the demo below.
I also recommend using the keys property because the data should be declared as [x, y], in your case it is the other way around. You can change that by setting this property.
Notice that in the Highcharts there is no such series as stack, it is just column.
API: https://api.highcharts.com/highcharts/series.line.keys
Demo: https://jsfiddle.net/BlackLabel/246phxum/
So this is how I did it eventually, the most suitable types of charts are line, and area chart.
Highcharts.chart("container", {
chart: {
type: 'line'
},
xAxis: {
type: "datetime",
labels: {
formatter: function () {
return Highcharts.dateFormat('%H:%M:%S.%L', this.value);
}
}
},
series: [{
name: "A",
type: "area",
color: "#BB000B",
keys: ["y", "x"],
data: [
[0.58, 1604244900],
[0.59733333333, 1604244915],
[0.6, 1604244930],
[0.6, 1604244945],
[0.6, 1604244960],
[0.6, 1604244975],
[0.612, 1604244990]
]
},
{
name: "B",
type: "line",
color: "#FF00F0",
keys: ["y", "x"],
data: [
[2, 1604244900],
[2, 1604244915],
[2, 1604244930],
[2, 1604244945],
[2, 1604244960],
[2, 1604244975],
[2, 1604244990],
[2, 1604245005]
]
}, {
name: 'C',
keys: ['y', 'x'],
data: [
[1, 1604244900],
[1, 1604244915],
[1, 1604244930],
[1, 1604244945],
[1, 1604244960],
[1, 1604244975],
[1, 1604244990],
[1, 1604245005]
]
}
]
});
I have created a network topography map using react-3d-graph and I am trying to access functions which are native to react-3d-graph outside of the graph itself. For example, I have a button which needs to utilize highlight behavior to highlight an individual node and its related nodes/links. Is there a way to do this? Here is the code for the graph:
const myConfig = {
"automaticRearrangeAfterDropNode": false,
"collapsible": true,
"height": 700,
"highlightDegree": 1,
"highlightOpacity": 0.2,
"linkHighlightBehavior": true,
"maxZoom": 8,
"minZoom": 0.1,
"nodeHighlightBehavior": true,
"panAndZoom": false,
"staticGraph": false,
"width": 1100,
"d3": {
"alphaTarget": 0.05,
"gravity": -200,
"linkLength": 300,
"linkStrength": 1
},
"node": {
"color": "#57a3ff",
"fontColor": "black",
"fontSize": 12,
"fontWeight": "bold",
"highlightColor": "red",
"highlightFontSize": 12,
"highlightFontWeight": "bold",
"highlightStrokeColor": "SAME",
"highlightStrokeWidth": 1.5,
"labelProperty": "name",
"mouseCursor": "pointer",
"opacity": 1,
"renderLabel": true,
"size": 450,
"strokeColor": "none",
"strokeWidth": 1.5,
"svg": "",
"symbolType": "square"
},
"link": {
"color": "#d3d3d3",
"opacity": 1,
"semanticStrokeWidth": false,
"strokeWidth": 4,
"highlightColor": "blue"
}
};
And here is the Graph component.
<Graph
id="graph-id"
data={data}
config={myConfig}
onClickNode={this.props.toggle}
onClickGraph={onClickGraph}
onClickLink={onClickLink}
/>
The function I am trying to access is "nodeHighlightBehavior". Is there a way to do this?
Is there any angularjs library that can draw a chart with stacked bars + lines? Like this:
I'm looking for any library that supports this, with angular directives. I've found angular-nvd3-directives, that supports multicharts (combined chart types), but I don't think it supports bar stacking, only grouping.
I know that these questions are not well suited to SO, I'm looking for ANY, ONE, lib, not recommendations. (also it has to be free for commercial use)
The ZingChart-AngularJS directive exposes the entire ZingChart library, which supports mixed charts. It's free for commercial use. I made a demo on CodePen of what you're looking for.
Here's what your JS would look like:
var app = angular.module('myApp', ['zingchart-angularjs']);
app.controller('MainController', function($scope) {
$scope.myJson = {
"type": "mixed",
"background-color": "white",
"plot": {
"stacked": true
},
"series": [{
"type": "bar",
"values": [25, 30, 15, 20, 25],
"stack": 1,
"background-color": "#4372c1",
"hover-state": {
"visible": false
},
}, {
"type": "bar",
"values": [20, 10, 30, 25, 15],
"stack": 1,
"background-color": "#ea4204",
"hover-state": {
"visible": false
},
}, {
"type": "line",
"values": [25, 30, 15, 20, 25],
"line-color": "#38408c",
"marker": {
"background-color": "#38408c",
"border-color": "#38408c"
},
"hover-state": {
"visible": false
}
}, {
"type": "line",
"values": [25, 30, 15, 20, 25],
"line-color": "#38408c",
"marker": {
"background-color": "#38408c",
"border-color": "#38408c"
},
"hover-state": {
"visible": false
},
},]
};
});
angular-nvd3 supports this.
All you have to do is set bars1.stacked=true and bars2.stacked=true
http://plnkr.co/edit/2gSaYHgNkuNjbj9SGrWt?p=preview
$scope.options = {
chart: {
type: 'multiChart',
...
bars1: {stacked:true},
bars2: {stacked:true},
...
};
}
}