ANYCHART - PERT Chart, how to add horizontal scroll - anychart

We are using Anychart Version 7.13 to create a PERT Chart in our application. Our data has a series of tasks with predecessors that require the chart to scroll horizontally. Our chart is getting truncated and we have tried to adjust chart.width in both % and PX but not able to enable horizontal scroll.
Any help will be most appreciated.
Thanks
VikasScreenshot showing truncation on right

Also, you should adjust spacing between milestones and milestones size in %. This will allow the pert chart fitting into the stage width. I prepared a sample for you below, the chart is scrollable. Please, pay attention to CSS style, stage settings and size/spacing settings. Probably, you should try other values in % exactly for your pert chart.
anychart.onDocumentReady(function () {
// create data
var data = [
{id: "1", duration: 1, name: "Task A"},
{id: "2", duration: 3, name: "Task B", dependsOn:["1"]},
{id: "3", duration: 4, name: "Task C", dependsOn:["2"]},
{id: "4", duration: 1, name: "Task D", dependsOn:["3"]},
{id: "5", duration: 2, name: "Task E", dependsOn: ["4"]},
{id: "6", duration: 2, name: "Task F", dependsOn: ["5"]},
{id: "7", duration: 1, name: "Task G", dependsOn: ["6"]},
{id: "8", duration: 2, name: "Task H", dependsOn: ["7"]},
{id: "9", duration: 3, name: "Task I", dependsOn: ["8"]},
{id: "10", duration: 2, name: "Task J", dependsOn: ["9"]}
];
// create a chart
var chart = anychart.pert();
//create stage
var stage = anychart.graphics.create("container");
//set stage width
stage.width(2000);
// adjsut milestones size in %
chart.milestones().size('5%');
//adjust spacing in %
chart.horizontalSpacing("9%");
// set chart data
chart.data(data, "as-table");
//render chart
chart.container(stage).draw();
});
html, body, #container {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow-x: scroll;
}
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-base.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-pert.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-exports.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.1.0/js/anychart-ui.min.js"></script>
<link href="https://cdn.anychart.com/releases/8.1.0/css/anychart-ui.min.css" rel="stylesheet"/>
<div id="container"></div>

Related

How to sort the array which is in key value pair in react?

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
const itemsData = [
{
key: 1,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
{
key: 2,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
{
key: 3,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
];
`
I am trying to filter this array. Just to get a new array as only with price array. Please help me to make a new array that has only price data
const price = [245,245,245]
You want to use map function on an array and transform the objects inside of it to a new value. Something like this
const itemsData = [
{
key: 1,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
{
key: 2,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
{
key: 3,
src: "https://www.davidjones.com/productimages/cart/1/2384359_21556984_6888675.jpg",
title: "Nautica ANTIGUA PADDED JACKET DARK NAVY",
price: 245,
colour: "459 DARK NAVY",
Size: "M",
Qty: "1",
},
];
const prices = itemsData.map(item => item.price)
console.log(prices)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
It's a simple mapping: itemsData.map(item => item.price)
Also, it's not really React related, more like a Javascript question.
itemsData.filter(item=>item.key === 1);
You can filter any item in this array like this!

how to show milliseconds in points in vis timeline in js

Is there anyway that we can show milliseconds of vis timeline in points for ex: 0.2 instead to 200 and 0.00 istead of 000
The format of the time axis can be controlled with the format configuration option, this is described in this section of the documnetation. Full details on the supported formatting syntax can be found in the moment.js documentation. If the syntax you'd like isn't supported you can write your own function to complete the formatting.
From your description I believe you'd like to display in the format <second>.<fractional seconds>. This would be achieved with the millisecond format s.SSS.
An example options object for vis-timeline with this option set:
var options = {
format: {
minorLabels: {
millisecond: 's.SSS',
}
}
};
Code snippet with this option set:
// DOM element where the Timeline will be attached
var container = document.getElementById("visualization");
// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet([
{id: 1, content: "item 1", start: "2022-07-20 13:52:10.001"},
{id: 2, content: "item 2", start: "2022-07-20 13:52:10.250"},
{id: 3, content: "item 3", start: "2022-07-20 13:52:11.100"},
{id: 4, content: "item 4", start: "2022-07-20 13:52:10.000", end: "2022-07-20 13:52:10.900"},
{id: 5, content: "item 5", start: "2022-07-20 13:52:10.800"},
{id: 6, content: "item 6", start: "2022-07-20 13:52:10.990", type: "point"},
{id: 7, content: "item 7", start: "2022-07-20 13:52:10.000", end: "2022-07-20 13:52:11.200"},
]);
// Configuration for the Timeline
var options = {
format: {
minorLabels: {
millisecond: 's.SSS',
}
}
};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
body,
html {
font-family: sans-serif;
}
<script src="https://visjs.github.io/vis-timeline/standalone/umd/vis-timeline-graph2d.min.js"></script>
<link href="https://visjs.github.io/vis-timeline/styles/vis-timeline-graph2d.min.css" rel="stylesheet"/>
<div id="visualization"></div>

Plotly tick labels misaligned in stacked horizontal bar chart

I am having trouble getting the yaxis tick labels to align to the bars properly when stacking horizontal bars by using base (my use case is a timeline view so i need empty spaces in between the stacked bars, thus why i am using base)
here is a codepen showcasing the issue: https://codepen.io/dan-wiegand/pen/GRMwKGP?editors=0010
var data = [{
type: 'bar',
x: [0, 10, 10, 0],
base: [0, 10, 20, 30],
y: ['trace 1', 'trace 1', 'trace 1', 'trace 1'],
orientation: 'h'
}, {
type: 'bar',
x: [0, 10, 0, 10],
base: [0, 10, 20, 30],
y: ['trace 2', 'trace 2', 'trace 2', 'trace 2'],
orientation: 'h'
}, {
type: 'bar',
x: [10, 0, 10, 0],
base: [0, 10, 20, 30],
y: ['trace 3', 'trace 3', 'trace 3', 'trace 3'],
orientation: 'h'.
}];
const layout = {
yaxis: {
showgrid: true
}
};
Plotly.newPlot('myDiv', data, layout);
(code required to post codepen link)
for those familiar with flex box, it's visually like the difference between space-around and space-between (bars being space between and ticks being space around)
My issue is visible below
and here it is in my actual case - if they all looked like "Copy Valence" that would be perfect
i dont care if the labels are along the axis lines or in the empty spaces, as long as the labels and the bars are aligned! In a perfect world the chart would be aligned like below, with the tick labels in the space between the ticks and the bars between ticks
question is tagged with python and javascript. Solution on python but concept same across languages
for each trace use a separate yaxis y, y2, y3
in layout set domain of each yaxis
import plotly.graph_objects as go
data = [
{
"type": "bar",
"x": [0, 10, 10, 0],
"base": [0, 10, 20, 30],
"y": ["trace 1", "trace 1", "trace 1", "trace 1"],
"orientation": "h",
"yaxis": "y",
},
{
"type": "bar",
"x": [0, 10, 0, 10],
"base": [0, 10, 20, 30],
"y": ["trace 2", "trace 2", "trace 2", "trace 2"],
"orientation": "h",
"yaxis": "y2",
},
{
"type": "bar",
"x": [10, 0, 10, 0],
"base": [0, 10, 20, 30],
"y": ["trace 3", "trace 3", "trace 3", "trace 3"],
"orientation": "h",
"yaxis": "y3",
},
]
go.Figure(data).update_layout(
{
ax: {"showgrid": True, "domain": [i * 0.33, (i + 1) * 0.33]}
for i, ax in enumerate(["yaxis", "yaxis2", "yaxis3"])
}
)

How to in this Reactjs file get images height and width before using an array

I learns Reactjs and trying to get images height and widths in this file to calculate the Ratio.
I havet this file albumData.js that looks like this:
// WEEK 1
import photo11 from '../images/weeks/1/DlGoaxEX0AAjY-7.jpg'
import photo12 from '../images/weeks/1/4olpqsvfte5rubn47j936z7c5vn9lff.jpeg'
import photo13 from '../images/weeks/1/9tlnx2sudu05jqxwij2evyvaifkrvbc.jpeg'
// WEEK 2
import photo21 from '../images/weeks/2/2.jpg'
import photo23 from '../images/weeks/2/original.jpg'
import photo22 from '../images/weeks/2/1_vtY9uCjeKSa1jIXm504jlg.jpeg.jpg'
export const albums = [
{
route: "1",
id: "album1",
data: [
{ id: "week 1-1", key: "1", backgroundImage: photo11, ratio: 768/1024, background: "rgb(56, 230, 236)", title: "week 1", description: "some desc" },
{ id: "week 1-2", key: "2", backgroundImage: photo12, ratio: 0.66771819137, background: "rgb(56, 230, 236)", title: "week 1", description: "some desc" },
{ id: "week 1-3", key: "3", backgroundImage: photo13, ratio: 0.74973711882, background: "rgb(56, 230, 236)", title: "week 1", description: "some desc" },
]
},
{
route: "2",
id: "album2",
data: [
{ id: "week 2-1", key: "1", backgroundImage: photo21, ratio: 0.75, background: "rgb(56, 230, 236)", title: "week 2", description: "some desc" },
{ id: "week 2-2", key: "2", backgroundImage: photo22, ratio: 0.75, background: "rgb(56, 230, 236)", title: "week 2", description: "some desc" },
{ id: "week 2-3", key: "3", backgroundImage: photo23, ratio: 0.56145833333, background: "rgb(56, 230, 236)", title: "week 2", description: "some desc" },
]
}
]
I call it from different locations like this
import { albums } from '../albumData'
My problem that I can't solve is that I need to input the images ratio inside the export const albums
Before I call and use the import { albums } from '../albumData' the array data in albums must have the ratio filled in from the actual images imports. I do that manually now but there will be 10.000 images.
The image Ratio is the width divided by the height!
I tried using React hooks but think that require a function something. Is there some static way in React to run this before using the albums?
Please advice

Set font sizes on individual labels in anychart

I have a pie chart that I'm creating using anychart.
The pie chart labels are all using the correct font-family and color, but what I want to do is be able to set different font sizes for each piece. I want to set the font size to be larger on the largest slice.
Here is my Fiddle
Here is my javascript
<script type="text/javascript">
var chart;
var labels;
anychart.onDocumentReady(function () {
//dataset
var data = anychart.data.set([
{ name: "$0-$50,000", value: 68, labelText: "68%", toolTip: "68%", title: "$0-$50,000" },
{ name: "$50,000-$100,000", value: 13, labelText: "13%", toolTip: "13%", title: "$50,000-$100,000" },
{ name: "$100,000-$150,000", value: 6, labelText: "6%", toolTip: "6%", title: "$100,000-$150,000" },
{ name: "$150,000-$250,000", value: 6, labelText: "6%", toolTip: "6%", title: "$150,000-$250,000" },
{ name: "$250,000 - plus", value: 7, labelText: "7%", toolTip: "7%", title: "$250,000 - plus" }
])
//set chart variable
chart = anychart.pie(data);
//Set labels to pull from data
labels = chart.labels();
labels.textFormatter('{%labelText}');
//Format tooltip content and styles
var tooltip = chart.tooltip();
tooltip.textFormatter('{%toolTip}');
tooltip.titleFormatter('{%title}');
tooltip.separator(true);
tooltip.fontFamily('PT Sans');
tooltip.fontSize(18);
tooltip.title().fontFamily('PT Sans');
tooltip.title().fontSize(18);
tooltip.title().align('center');
//adjust legend
var legend = chart.legend();
legend.enabled(true);
legend.position("left");
legend.align("center");
legend.itemsLayout("vertical");
legend.fontFamily('PT Sans');
//adjust font
var labels = chart.labels();
labels.fontColor('white');
labels.fontFamily('PT Sans');
labels.fontSize(36);
//create title
var title = chart.title();
title.text("68% of Rollovers Involve Less Than $50,000");
title.enabled(true);
title.fontColor('Red');
title.fontSize('48');
title.fontFamily('PT Sans');
title.fontWeight('700');
//inner radius makes this a doughnut chart instead of pie
chart.innerRadius("30%");
//define the container
chart.container("Container");
chart.animation(true);
//set delay to recall draw ch art to
chart.draw();
});
</script>
And here is a photo I've created in photoshop to show what I'm trying to achieve
The easiest way to do that is to put label object right into the data:
anychart.onDocumentReady(function() {
//dataset
var data = anychart.data.set([{
name: "$0-$50,000",
value: 68,
labelText: "68%",
toolTip: "68%",
title: "$0-$50,000",
label: {
fontColor: "Blue",
fontSize: 20
}
}, {
name: "$50,000-$100,000",
value: 13,
labelText: "13%",
toolTip: "13%",
title: "$50,000-$100,000",
label: {
fontColor: "Blue",
fontSize: 10
}
}, {
name: "$100,000-$150,000",
value: 6,
labelText: "6%",
toolTip: "6%",
title: "$100,000-$150,000",
label: {
fontColor: "Blue",
fontSize: 9
}
}, {
name: "$150,000-$250,000",
value: 6,
labelText: "6%",
toolTip: "6%",
title: "$150,000-$250,000",
abel: {
fontColor: "Green",
fontSize: 8
}
}, {
name: "$250,000 - plus",
value: 7,
labelText: "7%",
toolTip: "7%",
title: "$250,000 - plus",
label: {
fontColor: "Red",
fontSize: 7
}
}]);
//set chart variable
chart = anychart.pie(data);
chart.overlapMode(true);
//Set labels to pull from data
labels = chart.labels();
labels.textFormatter('{%labelText}');
//Format tooltip content and styles
var tooltip = chart.tooltip();
tooltip.textFormatter('{%toolTip}');
tooltip.titleFormatter('{%title}');
tooltip.separator(true);
tooltip.fontFamily('PT Sans');
tooltip.fontSize(18);
tooltip.title().fontFamily('PT Sans');
tooltip.title().fontSize(18);
tooltip.title().align('center');
//adjust legend
var legend = chart.legend();
legend.enabled(true);
legend.position("left");
legend.align("center");
legend.itemsLayout("vertical");
legend.fontFamily('PT Sans');
//adjust font
//var labels = chart.labels();
labels.fontColor('white');
labels.fontFamily('PT Sans');
//create title
var title = chart.title();
title.text("68% of Rollovers Involve Less Than $50,000");
title.enabled(true);
title.fontColor('Red');
title.fontSize('48');
title.fontFamily('PT Sans');
title.fontWeight('700');
//inner radius makes this a doughnut chart instead of pie
//chart.innerRadius("30%");
//define the container
chart.container("container");
chart.animation(true);
//set delay to recall draw ch art to
chart.draw();
});
<script src="https://cdn.anychart.com/js/7.12.0/anychart-bundle.min.js"></script>
<div id="container"></div>
Label object goes like this:
label: {
fontColor: "Blue",
fontSize: 20
}
Here is a sample on jsfiddle: http://jsfiddle.net/g3r57cee/
Some more information on labels can be found at http://docs.anychart.com/latest/Common_Settings/Labels

Resources