CanvasJs not displaying line in .asp - asp.net

Guys the problem i have with it is that i am not able to see the line chart's line and points. i am pretty sure that the chart is working because when i hover across it, i am able to see the data points. Please help, thanks!
This is the JavaScript for it.
<script type = "text/javascript" >
window.onload = function () {
var dataPoints = [{ y: 10 }];
var chart = new CanvasJS.Chart("chartContainer", {
backgroundColor: "red",
title: {
text: "Dynamic Data"
},
axisY: {
},
data: [{
type: "spline",
color: "yellow",
dataPoints: dataPoints
}]
});
chart.render();
var yVal = 15, updateCount = 0;
var updateChart = function () {
yVal = yVal;
updateCount++;
dataPoints.push({
y: yVal
});
chart.options.title.text = "Update " + updateCount;
chart.render();
};
// update chart every second
setInterval(function () { updateChart() }, 1000);
}
</script>
This is the body for it.
<div id = "chartContainer" style = "height: 300px; width: 100%;" />

I am unable to reproduce the issue.Can you share more details like the browser & CanvasJS library version. Here is a working fiddle for your code without any modification.
var dataPoints = [{ y: 10 }];
var chart = new CanvasJS.Chart("chartContainer", {
backgroundColor: "red",
title: {
text: "Dynamic Data"
},
axisY: {
},
data: [{
type: "spline",
color: "yellow",
dataPoints: dataPoints
}]
});
chart.render();
var yVal = 15, updateCount = 0;
var updateChart = function () {
yVal = yVal;
updateCount++;
dataPoints.push({
y: yVal
});
chart.options.title.text = "Update " + updateCount;
chart.render();
};
// update chart every second
setInterval(function () { updateChart() }, 1000);

Related

highchart map create marker by click and get lat long coordinates

I recently started using the map plugin. And Faced the problem of creating markers on click and displaying latitude and longitude on world map. Maybe someone has an example of how to implement this. Thank you for your assistance.
You can use the click event for a chart and series, calculate lat and lon values and add new point to the mappoint series.
Highcharts.mapChart('container', {
chart: {
map: 'custom/world-continents',
events: {
click: function(e) {
const latlon = this.fromPointToLatLon({
x: e.xAxis[0].value,
y: e.yAxis[0].value
});
this.series[1].addPoint(latlon);
}
}
},
plotOptions: {
map: {
events: {
click: function(e) {
const {
chart,
xAxis,
yAxis
} = this;
const latlon = chart.fromPointToLatLon({
x: xAxis.toValue(e.x),
y: yAxis.toValue(e.y)
});
chart.series[1].addPoint(latlon);
}
}
}
},
...
series: [{
...
}, {
type: 'mappoint',
colorAxis: null,
enableMouseTracking: false,
color: 'red',
dataLabels: {
allowOverlap: true,
formatter: function() {
const {
lat,
lon
} = this.point;
return 'Lat: ' + (lat.toFixed(2)) + '<br>Lon: ' + (lon.toFixed(2))
}
}
}]
});
Live demo: https://jsfiddle.net/BlackLabel/6p1bv0jn/
API Reference:
https://api.highcharts.com/class-reference/Highcharts.Chart#transformToLatLon
https://api.highcharts.com/highmaps/chart.events.click
https://api.highcharts.com/highmaps/plotOptions.map.events.click

fullCalendar: Events aren't shown where expected on the grid

Looked through the docs, but don't see why the events are placed incorrectly in my node app:
Global.js:
var eventList = [];
document.addEventListener('DOMContentLoaded', function() {
var eventDesc = {};
eventDesc = { title: 'Test', start: '2019-10-22', backgroundColor:'red' }; eventList.push( eventDesc );
eventDesc = { title: 'Test2', start: '2019-10-23T10:00:00', end: '2019-10-23T11:00:00', backgroundColor:'blue' }; eventList.push( eventDesc );
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
defaultView: "timeGridWeek",
height: "auto",
slotDuration: "00:60:00",
events: eventList,
plugins: [ 'dayGrid', 'timeGrid' ]
}
);
calendar.render();
});
Getting the following view (expect the blue event to be at 10 am on the grid, but it's off the grid entirely):
grid view

Full calendar - add text to day when there is no event

Would it be possible to add background text in full calendar when there is no event found for day, need help please
e.g
Just an idea:
$('#calendar').fullCalendar({
defaultView: 'month',
events: [{
title: 'event',
start: '2017-01-05 11:00',
end: '2017-01-06 13:00',
}, {
title: 'event 2',
start: '2017-01-18'
}],
dayRender: function(date, cell) {
cell.append('<div class="unavailable">Unavailable</div>');
},
eventAfterAllRender: function(view) {
var dayEvents = $('#calendar').fullCalendar('clientEvents', function(event) {
if (event.end) {
var dates = getDates(event.start, event.end);
$.each(dates, function(index, value) {
var td = $('td.fc-day[data-date="' + value + '"]');
td.find('div:first').remove();
});
} else {
var td = $('td.fc-day[data-date="' + event.start.format('YYYY-MM-DD') + '"]');
td.find('div:first').remove();
}
});
}
});
function getDates(startDate, endDate) {
var now = startDate,
dates = [];
while (now.format('YYYY-MM-DD') <= endDate.format('YYYY-MM-DD')) {
dates.push(now.format('YYYY-MM-DD'));
now.add('days', 1);
}
return dates;
};
Try this fiddle.

Custom tooltip in Chart.js

I'm trying to display custom tool tips with Chart.js depending on the data classification. I want to display:
1: Tooltip1
2: Tooltip2
3: Tooltip2
Following is the code.
<script type="text/javascript" language="javascript">
var pieData = [
{
value: parseInt(document.getElementById("<%= txtPendingCount.ClientID %>").value, 0),
color: "#f5170a",
highlight: "#f85248",
label: "1"
},
{
value: parseInt(document.getElementById("<%= txtCompletedCount.ClientID %>").value, 0),
color: "#ce5e0c",
highlight: "#cf7d40",
label: "2"
},
{
value: parseInt(document.getElementById("<%= txtWithheldCount.ClientID %>").value, 0),
color: "#f4cd0c",
highlight: "#f7de62",
label: "3"
}
];
window.onload = function () {
var ctx = document.getElementById("chart-area").getContext("2d");
window.myPie = new Chart(ctx).Pie(pieData);
};
</script>
Can anyone please suggest how to do this?
Thanks.
In the example you can see how to do this, you can note that i use doughut but is the same idea to do this with pie chart:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="chart-area" style="display:inline;"></canvas>
<script>
var doughnutData = [
{
value: 200,
color: "#FFF",
label:"White",
},
{
value: 200,
color: "#bb2028",
label:"Red",
},
{
value: 80,
color: "#d97128" ,
label:"Orange",
},
{
value: 40,
color: "#fada09",
label:"Yellow",
},
{
value: 100,
color: "#6bb345",
label:"Light Green",
},
{
value: 60,
color: "#b4aea7",
label:"Gray",
},
{
value: 200,
color:"#2d5f2e",
fillColor:"#2d5f2e",
label:"Green",
}
];
window.onload = function(){
var helpers = Chart.helpers;
var canvas= document.getElementById("chart-area");
var ctx = canvas.getContext("2d");
var globalChartConfig = {
responsive : true,
tooltipTemplate: "<%if (label){%>Label Color: <%=label%>: <%}%> <%= value %>",
}
window.myDoughnut = new Chart(ctx).Doughnut(doughnutData, globalChartConfig);
};
</script>

D3: Links are not visible in force layout graph when I modified the code to link nodes by a defined key instead of index

I am working off of mbostock's Mobile Patent Suit
I modified the data format to link nodes by a defined key (name and type) instead of by index. I have tried modifying the tick function and selecting and and appending, but nothing seems to work.
Here's my code on JsFiddle
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.node circle {
/*stroke: #fff;*/
cursor: pointer;
stroke: #3182bd;
stroke-width: 1.5px;
}
.node text {
font: 10px sans-serif;
pointer-events: none;
text-anchor: middle;
}
.link {
stroke-opacity: .6;
stroke-width: 1.5px;
stroke: #666;
fill: none;
}
.link.deliverFor {
stroke: green;
}
.link.sentTo {
stroke-dasharray: 0,2 1;
}
/* color of nodes based on type */
circle.emailAddress {
fill: blue;
}
circle.ip {
fill: red;
}
circle.missing {
fill: "#3182bd";
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var color = d3.scale.category20();
var linkDistanceScale = d3.scale.linear()
.domain([10, 5000])
.range([2, 300])
.clamp(true);
var force = d3.layout.force()
.linkDistance(30)
.charge(-120)
.size([width, height]);
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var graph = {
"nodes": [
{
"name": "foo#pp.com",
"type": "emailAddress",
"size": 1234
},
{
"name": "192.168.0.1",
"type": "ip",
"size": 870
},
{
"name": "bar#pp.com",
"type": "emailAddress",
"size": 3423
}
],
"undirectedNeighbors": [
{
"label": "deliverFor",
"left": {
"name": "foo#pp.com",
"type": "emailAddress"
},
"right": {
"name": "192.168.0.1",
"type": "ip"
},
"weight": 366
},
{
"left": {
"type": "emailAddress",
"name": "foo#pp.com"
},
"right": {
"type": "emailAddress",
"name": "bar#pp.com"
},
"label": "sentTo",
"weight": 777
}
]
};
var my_nodes = graph.nodes.slice(),
my_neighbors = graph.undirectedNeighbors.slice();
console.log("my_neighbors", my_neighbors);
var hash_lookup = [];
// make it so we can lookup nodes by entry (name: x, type, y) in O(1):
my_nodes.forEach( function(node) {
var key = {name: node.name, type: node.type};
hash_lookup[key] = node;
});
// tell d3 where to find nodes info
my_neighbors.forEach( function(link) {
var left = link.left;
var right = link.right;
var leftKey = {name: left.name, type: left.type};
var rightKey = {name: right.name, type: right.type};
link.source = hash_lookup[leftKey];
link.target = hash_lookup[rightKey];
});
console.log("my_neighbors", my_neighbors);
console.log("my_nodes", my_nodes);
console.log("neighobrs", graph.undirectedNeighbors);
/************** SETUP FORCE LAYOUT ****************/
force
.nodes(my_nodes)
.links(my_neighbors)
.linkDistance( function(d) {
console.log("linkDistance", d);
return linkDistanceScale(d.weight);
})
.start();
console.log("force.links()", force.links());
/************** DRAW PATHS ****************/
var link = svg
.append("svg:g") // the "curves" is drawn inside this container
.selectAll("path")
.data(force.links())
.enter()
.append("svg:path")
// .attr("class", "link")
.attr("class", function(d) {
return "link " + d.type;
});
/************** DRAW CIRCLES ****************/
var node = svg
.selectAll(".node")
.data(force.nodes());
var circle = node
.enter()
.append("circle")
.attr("class", "node")
.attr("r", function(d) {
console.log("circle d", d);
return Math.sqrt(d.size) / 10 || 4.5;
})
.attr("class", function(d) {
return d.type || "missing"; // color circle based on circl.* defined above
})
.call(force.drag);
/************** DISPLAY NAME WHEN CURVER HOVER OVER CIRCLE ****************/
var text = circle.append("title")
.text(function(d) { return d.name; });
force.on("tick", function() {
link.attr("d", function(d) {
var dx = d.target.x - d.source.x,
dy = d.target.y - d.source.y,
dr = Math.sqrt(dx * dx + dy * dy);
return "M" + d.source.x + "," + d.source.y + "A" + dr + "," + dr + " 0 0,1 " + d.target.x + "," + d.target.y;
});
node
.attr("transform", function(d) {
return "translate(" + d.x + "," + d.y + ")"; });
});
</script>
Any insight would be greatly appreciated.
Leaving aside whether or not this approach is a good idea, the problem is that you're attempting to use objects as keys in an object (your hash_lookup). That isn't something that works in JavaScript. A quick, dirty, hack fix would just be to convert the map keys into strings before using them
var hash_lookup = {};
// make it so we can lookup nodes by entry (name: x, type, y) in O(1):
my_nodes.forEach( function(node) {
var key = JSON.stringify({name: node.name, type: node.type});
hash_lookup[key] = node;
});
// tell d3 where to find nodes info
my_neighbors.forEach( function(link) {
var left = link.left;
var right = link.right;
var leftKey = JSON.stringify({name: left.name, type: left.type});
var rightKey = JSON.stringify({name: right.name, type: right.type});
link.source = hash_lookup[leftKey];
link.target = hash_lookup[rightKey];
});

Resources