Zingchart real time data feed - zingchart

I have this Zingchart(gauge type) which displays random numbers from 1 to 100 using JS. I need to achieve the same via PHP. How can I do this? What are the necessary changes that needs to be done?
window.feed = function(callback) {
var tick = {};
tick.plot0 = Math.ceil(Math.random() * 100);
callback(JSON.stringify(tick));
refresh:{
type:"feed",
transport:"js",
url:"feed()",
interval:1000,
resetTimeout:1000
},

The necessary changes to work in php would be to set up a endpoint to hit. If you did something like:
window.feed = function(callback) {
var tick = {};
tick.plot0 = Math.ceil(Math.random() * <?php $phpValue ?>);
callback(JSON.stringify(tick));
The variable $phpValue would not work for a Javascript feed function because that value would printed only ONE time as the server compiles the php ONCE.
What to do then?
You want to add a proper url endpoint which returns the tick format. That would look something like this:
refresh: {
type: 'feed',
transport: 'http',
url: 'https://us-central1-zingchart-com.cloudfunctions.net/public_http_feed?min=0&max=50&plots=2',
interval: 200
}
Where the url returns the following data structure:
[{
plot0: 3,
plot1: 18,
'scale-x': "13:33:48" // optional scale-x argument to produce [x,y] plotting
}]
You can read more on the http docs.
Solution
Demo here
// define top level feed control functions
function clearGraph() {
zingchart.exec('myChart', 'clearfeed')
}
function startGraph() {
zingchart.exec('myChart', 'startfeed');
}
function stopGraph() {
zingchart.exec('myChart', 'stopfeed');
}
// window.onload event for Javascript to run after HTML
// because this Javascript is injected into the document head
window.addEventListener('load', () => {
// Javascript code to execute after DOM content
//clear start stop click events
document.getElementById('clear').addEventListener('click', clearGraph);
document.getElementById('start').addEventListener('click', startGraph);
document.getElementById('stop').addEventListener('click', stopGraph);
// full ZingChart schema can be found here:
// https://www.zingchart.com/docs/api/json-configuration/
const myConfig = {
//chart styling
type: 'line',
globals: {
fontFamily: 'Roboto',
},
backgroundColor: '#fff',
title: {
backgroundColor: '#1565C0',
text: 'Real-Time Line Chart',
color: '#fff',
height: '30x',
},
plotarea: {
marginTop: '80px'
},
crosshairX: {
lineWidth: 4,
lineStyle: 'dashed',
lineColor: '#424242',
marker : {
visible : true,
size : 9
},
plotLabel: {
backgroundColor: '#fff',
borderColor: '#e3e3e3',
borderRadius:5,
padding:15,
fontSize: 15,
shadow : true,
shadowAlpha : 0.2,
shadowBlur : 5,
shadowDistance : 4,
},
scaleLabel: {
backgroundColor: '#424242',
padding:5
}
},
scaleY: {
guide: {
visible: false
},
values: '0:100:25'
},
tooltip: {
visible: false
},
//real-time feed
refresh: {
type: 'feed',
transport: 'http',
url: 'https://us-central1-zingchart-com.cloudfunctions.net/public_http_feed?min=0&max=50&plots=1',
interval: 500,
},
plot: {
shadow: 1,
shadowColor: '#eee',
shadowDistance: '10px',
lineWidth:5,
hoverState: {visible: false},
marker:{ visible: false},
aspect:'spline'
},
series: [{
values: [],
lineColor: '#2196F3',
text: 'Blue Line'
},{
values: [],
lineColor: '#ff9800',
text: 'Orange Line'
}]
};
// render chart with width and height to
// fill the parent container CSS dimensions
zingchart.render({
id: 'myChart',
data: myConfig,
height: '100%',
width: '100%',
});
});
html, body {
height:100%;
width:100%;
margin:0;
padding:0;
}
#myChart {
margin: 0 auto;
height: 380px;
width: 98%;
box-shadow: 5px 5px 5px #eee;
background-color: #fff;
border: 1px solid #eee;
display: flex;
flex-flow: column wrap;
}
.controls--container {
display: flex;
align-items: center;
justify-content: center;
}
.controls--container button {
margin: 40px;
padding: 15px;
background-color: #FF4081;
border: none;
color: #fff;
box-shadow: 5px 5px 5px #eee;
font-size: 16px;
font-family: Roboto;
cursor: pointer;
transition: .1s;
}
.controls--container button:hover {
opacity: .9;
}
/*button movement*/
.controls--container button:active {
border-width: 0 0 2px 0;
transform: translateY(8px);
opacity: 0.9;
}
.zc-ref { display:none; }
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>ZingGrid: Blank Grid</title>
<script src="https://cdn.zingchart.com/zingchart.min.js"></script>
</head>
<body>
<!-- CHART CONTAINER -->
<div id="myChart">
<a class="zc-ref" href="https://www.zingchart.com">Powered by ZingChart</a>
</div>
<div class="controls--container">
<button id="clear">Clear</button>
<button id="stop">Stop</button>
<button id="start">Start</button>
</div>
</body>
</html>

Related

Extjs Loading Icon

I am looking to get a loading icon as below in Extjs. I came across Extjs loadMask but it is not exactly what I am looking for. Are there any other existing components that I could use and perhaps make changes to, to achieve this behavior and look? If not, any suggestions on how this could be implemented?
Updates: I am trying to add the icon for every row in a table and below is the code which is included as one of the items in a list under this.columns. However, nothing gets displayed on the rows. Am I missing something ?
{
xtype: 'actioncolumn',
sortable:false,
menuDisabled:true,
width:50,
hidden:false,
items: [{
xtype:'component',
cls:'spinner-circular',
height:50
}]
}
We made our own component to display loadicon as following :
it's just as simple as :
{
xtype: 'component',
cls: 'spinner-circular',
height: 50
}
with css being :
#keyframes spinner-circular {
to {transform: rotate(360deg);}
}
.spinner-circular:before {
content: '';
box-sizing: border-box;
position: absolute;
top: 50%;
left: 50%;
width: 50px;
height: 50px;
margin-top: -15px;
margin-left: -15px;
border-radius: 50%;
border: 1px solid #ccc;
border-top-color: #f48b31;
animation: spinner-circular .6s linear infinite;
}

Stripe Elements Icon Padding Issue

I'm using Stripe Elements on my site but running into some issues with the icon styling.
I've done some searching and found this link but they have closed the ticket saying the issue was fixed.
As you can see on my screenshot here the icon is flush to the edge and I'd like some padding to the left.
I've tried adding padding via my JS like so but it doesn't change anything.
var style = {
base: {
iconColor: "#fff",
padding: "5px 10px 5px 20px",
backgroundColor: "#a91537",
color: "#fff",
fontWeight: "400",
fontFamily: "Montserrat, sans-serif",
fontSize: "18px",
lineHeight: "80px",
fontSmoothing: "antialiased",
showIcon: false,
textIndent: "10px",
":-webkit-autofill": {
color: "#fff",
},
"::placeholder": {
color: "#fff",
},
},
invalid: {
color: "#fa775a",
iconColor: "#fa775a",
},
};
I've even tried adding it via CSS but because it's pulled in via an iframe my styling does nothing.
You need to be changing the style of the container you mount the Element to, not the Element itself. For example, if you were mounting your card element to #card-element you could add some basic styling like this:
<style>
#card-element {
padding: 12px;
}
</style>
<div id="card-element"></div>
You can read more about this here: https://stripe.com/docs/js/element/the_element_container?type=card

Material ui - How would i add small triangle in the corner?

I'm trying to get results such as this in my MUI Button -
http://jsfiddle.net/bcGdJ/3160/
I ended up with this, but it seems that both before and after css selectors doesn't work.
import React from "react";
import Button from "#material-ui/core/Button";
import Notifications from "#material-ui/icons/Notifications";
import "./box.css";
const styles = {
color: 'purple',
backgroundColor: 'gray',
minWidth: '40px',
minHeight: '40px',
borderRadius: 1,
position: "relative",
"&:before,&:after": {
content: '',
position: "absolute",
bottom: 0,
left: 0,
borderColor: "transparent",
borderStyle: "solid"
},
"&:before": {
borderWidth: "8px",
borderLeftColor: "#efefef",
borderBottomColor: "#efefef",
},
"&:after": {
borderRadius: "3px",
borderWidth: "5px",
borderLeftColor: "#fff", /* color of the triangle */
borderBottomColor: "#fff" /* color of the triangle */
}
};
function CustomizedInputs(props) {
return (
<div id="container">
<Button color="primary" style={styles}>
<Notifications />
</Button>
</div>
);
}
export default CustomizedInputs;
```
https://codesandbox.io/s/72jyr75461
Any help would be appreciated
Your code is nice but you missed some simple points.
You need to use content: "''" instead of content: "".
You need to use :: instead of : for before and after.
cssRoot: {
color: theme.palette.getContrastText(purple[500]),
backgroundColor: purple[200],
minWidth: "40px",
minHeight: "40px",
borderRadius: 1,
position: "relative",
"&::before,&::after": {
content: "''",
position: "absolute",
bottom: 0,
left: 0,
borderColor: "transparent",
borderStyle: "solid"
},
"&::before": {
borderWidth: "8px",
borderLeftColor: "#efefef",
borderBottomColor: "#efefef"
},
"&::after": {
borderRadius: "3px",
borderWidth: "5px",
borderLeftColor: "#fffff" /* color of the triangle */,
borderBottomColor: "#fffff" /* color of the triangle */
}
}
https://codesandbox.io/s/541v247qlp

Fabric js convert HTML code to IText

Is possible in fabric.js convert this HTML code to an IText:
<p>Hello <strong>John!</strong></p>
I have read the docs, but I can't find anything...
I have tried with this with no results:
var text = canvas.add(new fabric.IText('<p>Hello <strong>John!</strong></p>', {}));
There is no built-in parser. You need to use text content of element and apply different styles using styles property of IText.
DEMO
var canvas = new fabric.Canvas('c');
var text = new fabric.IText('Hello John!', {
fontSize: 20,
styles: {
0: {
6: {
fontWeight: 'bold'
},
7: {
fontWeight: 'bold'
},
8: {
fontWeight: 'bold'
},
9: {
fontWeight: 'bold'
},
10: {
fontWeight: 'bold'
},
}
}
})
canvas.add(text);
canvas {
border: 1px solid #999;
}
<script src="https://rawgit.com/kangax/fabric.js/master/dist/fabric.js"></script>
<p>Hello <strong>John!</strong></p>
<canvas id="c" width="300" height="300"></canvas>

Flot pie chart edges cut off

I have the following code showing a pie chart with Flot:
HTML
<div style="background-color: #000000">
<div id="divChartContainer" style="width: 50px; height: 50px"></div>
</div>
JS:
$(function () {
$.plot($('#divChartContainer'), [{data: 60, color: '#F0F0F0'},{data: 40, color: '#F68E22'}], {
series: {
pie: {
show: true,
stroke: { width: 2, color: '#F0F0F0'},
label: { show: false },
},
legend: { show: false }
}
});
});
This is also in a fiddle here. I'm not sure why the top, bottom, left and right edges are being cut off as I've told the chart to be 50px high and wide.
Following on the comment from mechenbier, you need to get the size of the pie smaller then the size of the container so that the stroke still stays inside the container. The easiest solution is setting the radius to 24 (it needs to be smaller then half the height/width of the container):
pie: {
show: true,
stroke: { width: 2, color: '#F0F0F0'},
label: { show: false },
startAngle: 3/2,
radius: 24
},
See this updated fiddle.

Resources