Problem:
I have a problem getting the event to use only one of the rows and not invade the others like it does now:
Objetive:
My intention is to do single row events, there will only be one event for each row something like this:
I tried to do it with css but fullcalendar moves the event to the right and there is no ccs tag that identifies it to be able to move it with css, instead it uses inset and I don't really understand how to achieve it.
There are 2 alternatives:
Find a way for the rows to adapt to the size of the events.
Somehow move the event that fullcalendar moves to the right.
The problem is with my little knowledge, I don't know how to do it.
Code with events thinned:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendario');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
timeZone: 'America/Guayaquil',
headerToolbar: {
start: 'today prev,next',
center: 'title',
end: 'dayGridMonth,timeGridWeek,listDay'
},
views: {
timeGrid: {
type: 'timeGrid',
//slotEventOverlap: false,
displayEventEnd: true,
duration: { days: 7 },
allDaySlot: false,
slotDuration: '00:30:00',
slotLabelFormat: {
hour: 'numeric',
minute: '2-digit',
hour12: false,
meridiem: false
},
slotLabelInterval: '00:30:00',
slotMinTime: '07:00:00',
slotMaxTime: '18:30:00',
expandRows: true,
buttonText: 'Semana',
nowIndicator: true,
}
},
//Funciones
dateClick: function(info){
alert('Dia seleccionado: ' + info.dateStr);
alert('Vista Actual: ' + info.view.type);
info.dayEl.style.backgroundColor = '#F2F2F2';
cFormAñadir('añadir', 'abrir');
},
//Eventos
eventSources: [{
events: [
{
title: 'Consulta ginecologia',
start: '2021-10-05T14:00:00',
duration: '2021-10-05T14:00:00',
allDay: false,
color: "#ed4245",
textColor: "#FFFFFF",
forceEventDuration: true
},
{
title: 'Consulta obstetricia',
start: '2021-10-05T13:00:00',
end: '2021-10-05T13:00:00',
allDay: false,
color: "#3AA95E",
textColor: "#FFFFFF"
},
{
title: 'Ecocardiograma',
start: '2021-10-05T13:30:00',
end: '2021-10-05T13:30:00',
allDay: false
},
{
title: 'Consulta obstetricia2',
start: '2021-10-06T13:00:00',
end: '2021-10-06T13:00:00',
allDay: false,
color: "#3AA95E",
textColor: "#FFFFFF"
},
],
color: "#FAA61A",
textColor: "#FFFFFF"
}]
});
calendar.render();
});
.fc-timegrid-col-events .fc-timegrid-event-harness{
height: 34px!important;
width: 100%!important;
}
.fc-timegrid-event-harness .fc-timegrid-event {
position: static;
}
.fc-timegrid-event-harness .fc-timegrid-event .fc-event-main {
line-height: 15px;
}
<link href="https://cdn.jsdelivr.net/npm/fullcalendar#5.9.0/main.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar#5.9.0/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="calendario"></div>
The problem is that your events all have the same start and end times. As far as fullCalendar is concerned, they take up 0 minutes. It's the same as if you hadn't specified an end property at all.
Of course this would make them undisplayable, so instead fullCalendar gives them a default duration of 1 hour - which is why they overlap into the next slot.
To solve this you can either:
Specify an end time 30 minutes later than the start time for each event.
Or
Change the defaultTimedEventDuration from 1 hour (the default) to 30 minutes, as I've done in the demo below.
In either case, your custom CSS is not required.
Documentation: https://fullcalendar.io/docs/defaultTimedEventDuration
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendario');
var calendar = new FullCalendar.Calendar(calendarEl, {
initialView: 'dayGridMonth',
timeZone: 'America/Guayaquil',
headerToolbar: {
start: 'today prev,next',
center: 'title',
end: 'dayGridMonth,timeGridWeek,listDay'
},
defaultTimedEventDuration: "00:30",
initialView: "timeGridWeek",
views: {
timeGrid: {
type: 'timeGrid',
//slotEventOverlap: false,
displayEventEnd: true,
duration: { days: 7 },
allDaySlot: false,
slotDuration: '00:30:00',
slotLabelFormat: {
hour: 'numeric',
minute: '2-digit',
hour12: false,
meridiem: false
},
slotLabelInterval: '00:30:00',
slotMinTime: '07:00:00',
slotMaxTime: '18:30:00',
expandRows: true,
buttonText: 'Semana',
nowIndicator: true,
}
},
//Funciones
dateClick: function(info){
alert('Dia seleccionado: ' + info.dateStr);
alert('Vista Actual: ' + info.view.type);
info.dayEl.style.backgroundColor = '#F2F2F2';
cFormAñadir('añadir', 'abrir');
},
//Eventos
eventSources: [{
events: [
{
title: 'Consulta ginecologia',
start: '2021-10-05T14:00:00',
duration: '2021-10-05T14:00:00',
allDay: false,
color: "#ed4245",
textColor: "#FFFFFF",
forceEventDuration: true
},
{
title: 'Consulta obstetricia',
start: '2021-10-05T13:00:00',
end: '2021-10-05T13:00:00',
allDay: false,
color: "#3AA95E",
textColor: "#FFFFFF"
},
{
title: 'Ecocardiograma',
start: '2021-10-05T13:30:00',
end: '2021-10-05T13:30:00',
allDay: false
},
{
title: 'Consulta obstetricia2',
start: '2021-10-06T13:00:00',
end: '2021-10-06T13:00:00',
allDay: false,
color: "#3AA95E",
textColor: "#FFFFFF"
},
],
color: "#FAA61A",
textColor: "#FFFFFF"
}]
});
calendar.render();
});
<link href="https://cdn.jsdelivr.net/npm/fullcalendar#5.9.0/main.min.css" rel="stylesheet"/>
<script src="https://cdn.jsdelivr.net/npm/fullcalendar#5.9.0/main.min.js"></script>
<div id="calendario"></div>
Related
I use a DrawChart method and try to set the logarithmic option to the yaxis to true without success:
The datas (for the series) contains :
"[{type:"bar",data:[1.19576304413727E-08,1.30322021618667E-07]}]"
I try to place the logarithmic : true option in several place without succes. For me it must be placed into the yaxis part.
Thank you in advance
chart.updateOptions({
series: datas,
chart: {
toolbar: {
show: showToolbar
},
animations: {
enabled: false
},
type: 'bar'
},
plotOptions: {
bar: {
horizontal: false,
columnWidth: '50%',
endingShape: 'rounded'
}
},
stroke: {
show: true,
width: 2,
colors: ['transparent']
},
xaxis: {
title: {
text: 'Masse'
},
categories: categories//,
//tickAmount: 10
},
yaxis: {
labels: {
formatter: function (value) {
//var ex;
return value.toExponential();
//return value;
}
},
title: {
text: unit
},
tickAmount: 10
//min: min,
//max: max,
//decimalsInFloat: 3
},
grid: {
padding: {
left: 50,
right: 50
}
},
legend: {
show: true,
position: 'bottom',
horizontalAlign: 'left',
showForSingleSeries: true,
showForNullSeries: true,
showForZeroSeries: true
},
})
I found the problem !
When you have log values really small (like 5.32E-9), the logarithm option doesnt work if you try to display the legend thrue a JS function.
So multiply by 1E10 the divide into the JS function (where you display the legend) by 1E10.
The tooltip in my Highchart is behaving strangely. It is living its own life. It doesn't show the tooltip of the point on which I hover, but shows the tooltip of any point randomly.
Here is a JSFiddle example: http://jsfiddle.net/AeV7h/9/
$(function () {
var data=[[28,0],[24,3],[16,10]];
var param= { WodTag: "cur_spd", Name: "Current speed", Color: "#C6C6C6", LineStyle: "Solid", SeriesType: "line", LineWidth: 2, TickInterval: null, MinValue: null, MaxValue: null, Decimals: 2 };
$('#container').highcharts({
chart: {
height: 700,
width: 400,
plotBorderWidth: 1,
plotBorderColor: '#E4E4E4',
},
xAxis: {
title: {
useHTML: true,
text: param.Name + "( m/s )",
},
gridLineWidth: 1,
min: param.MinValue,
max: param.MaxValue,
gridLineDashStyle: 'Dot',
tickInterval: param.TickInterval
},
yAxis: {
title: {
text: 'Depth(m)',
},
reversed: true,
tickLength: 50,
gridLineDashStyle: 'Dot'
},
title: {
text: null,
},
legend: {
enabled: false
},
credits: {
enabled: false
},
tooltip: {
useHTML: true,
formatter: function () {
return this.y;
}
},
series: [{
name: param.Name,
data: data,
color: param.Color,
dashStyle: param.LineStyle,
lineWidth: param.LineWidth,
type: "line"
}]
});
});
Can anyone help and tell me why it is behaving like this, and how I can fix it?
Your problem is that your data is not sorted by increasing X value. If you read the Series.data documentation it says that (API):
Note data must be sorted by X in order for the tooltip positioning and data grouping to work.
You should always sort your data like this before handing it over to Highcharts. Highcharts doesn't sort any data. Doing it by hand for your example your data should look like this:
var data=[[16,10],[24,3],[28,0]];
As in this JSFiddle demonstration, and everything works as intended.
I have a Highcharts chart which gets it's data from a JSON request.
function slowips(target){
var options = {
chart: {
renderTo: target,
type: 'spline',
borderColor: '#0072C6',
borderWidth: 3
},
title: {
text: 'Responsetime'
},
subtitle: {
text: 'Nr.1 is slowest'
},
legend: {
enabled: true,
layout: 'vertical',
align: 'right',
verticalAlign: 'middle'
},
yAxis: {
title: {
text: 'Milliseconds'
},
min: 0
},
exporting: {
enabled: false
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
month: '%e. %b',
year: '%Y'
},
labels: {
enabled: true,
},
minorTickLength: 0,
tickLength: 0,
},
plotOptions: {
spline: {
animation: false,
enableMouseTracking: false,
marker: {
enabled: false
}
}
},
series: [{}]
};
$.getJSON('graphs/test.php', function(data) {
options.series = data;
var chart = new Highcharts.Chart(options);
});
}
slowips();
This is an example JSON input:
[ { "name":"sddf", "data": [ ["2013-02-01 00:01:00", 2 ], ["2013-02-02 00:02:00", 2.55 ] ] } ]
Also tried:
[ { "name":"sddf", "data": [ [Date.UTC(12, 3, 09), 2 ], [Date.UTC(12, 3, 10), 2.55 ] ] } ]
The first JSON example renders a chart, but with incorrect X axis data. The second JSON does not render the chart.
Please help out!
You need to use timestamps, so when you load first JSON, then you need to parse it by Date.UTC() / Data.parse(), but functions cannot be places in json inside (as you have in second example).
I am attempting to create an area chart based on a timeline and everything works until I add a series marker. I have tried a few different patterns but can't get the chart to render with a marker.
Attempt 1: replace [x,y] item with [{x,y,marker}] object
data: [[1384219800000,2],
[{x:1384269600000,y:7,marker:{symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"}}],
[1384279900000,1]]
Attempt 2: replace [x,y] item with [x, {y,marker}] object
data: [[1384219800000,2],
[1384269600000, {y:7,marker:{symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"}}],
[1384279900000,1]]
This is the working area chart without the marker. This renders fine until I try to add the marker notation
$(function () {
$('#container').highcharts({
chart: {
type: 'area'
},
title: {
style: {
display: 'none'
}
},
subtitle: {
style: {
display: 'none'
}
},
credits: {
enabled: false
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: ''
},
min: 0,
minorGridLineWidth: 0,
gridLineWidth: 0,
alternateGridColor: null
},
legend: {
borderWidth: 0,
enabled: true,
align: 'right',
verticalAlign: 'top',
x: -5,
y: -15,
floating: true
},
plotOptions: {
area: {
stacking: 'normal',
lineColor: '#666666',
lineWidth: 1,
marker: {
lineWidth: 0,
lineColor: '#666666',
enabled: false
}
}
},
series:
[{
name: 'Items',
color: '#3399CC',
data: [[1384219800000,2],[1384269600000,7],[1384279900000,1]]
}],
navigation:
{
menuItemStyle: {
fontSize: '10px'
}
},
navigator: {
enabled: true
},
scrollbar: {
enabled: false
},
rangeSelector: {
enabled: false
}
});
});
Your first syntax is close to correct, except you need to drop the [] around the {} and enable the marker for that specific point:
data: [
[1384219800000,2],
{
x:1384269600000,
y:7,
marker:{
enabled: true,
symbol:"url(http://www.highcharts.com/demo/gfx/sun.png)"
}
},
[1384279900000,1]
]
Fiddle here.
I have a problem with my HighStock, I need another series from JSON.
My code in get_json.php
include('config.php');
$cp = $_REQUEST["c_prot"];
$r=("SELECT * FROM data WHERE cp='$cp'");
$result=mysql_query($r);
while($row = mysql_fetch_array($result)){
$date= strtotime($row['cas'])*1000; // timestamp
$values=hexdec($row['data']); // series1
$val=hexdec($row['src']); // series2
$array[]=array($date, $values,$val); //output array
}
echo json_encode($array);
JSON output is in correct format: [1364852734000, 557, 2884],....
But problem is, that I didn't find how to add second series from JSON to Highstock code
I would like to display in chart x-axis: timestamp
y-axis: series1->data
series2->src
chart now displays only on x-axis timestamp and on y-axis data...but series2 doesn't work:/
High Stock code:
<script>
$(function () {
$.getJSON('http://localhost/vojto/get_json.php?c_prot=<?=$_REQUEST['
c_prot '];?>', function (data) {
// Create the chart
$('#container').highcharts('StockChart', {
chart: { //zooming
zoomType: 'x',
height: 400,
},
legend: { //legenda
enabled: true,
align: 'left',
backgroundColor: '#FCFFC5',
borderColor: 'black',
borderWidth: 1,
layout: 'vertical',
verticalAlign: 'top',
y: 100,
shadow: true
},
rangeSelector: { //range selector
buttonTheme: {
width: 40,
},
buttonSpacing: 3, //mezera mezi buttony
enabled: true,
buttons: [{
type: 'minute',
count: 60,
text: 'Hour'
}, {
type: 'day',
count: 1,
text: 'Day'
}, {
type: 'week',
count: 1,
text: 'Week'
}, {
type: 'all',
text: 'Reset'
}]
},
title: { //title grafu
text: 'Chart'
},
series: [{ //serie
name: 'Data',
data: data,
color: '#57c72f',
marker: {
enabled: true,
radius: 3
},
shadow: true,
tooltip: {
valueDecimals: 2
}
}],
xAxis: { // X-osa
type: 'datetime',
title: {
text: 'Date/time axis',
},
minRange: 600000,
},
yAxis: {
min: 0,
},
navigator: {
series: {
color: '#57c72f',
fillOpacity: 0.3,
}
},
credits: {
enabled: false
},
tooltip: { // formátování hodnot po najetí kurzoru... hover
formatter: function () {
var s = '<b>' + Highcharts.dateFormat('DateTime ' + '%d-%m-%y ' + '%H:%M:%S', this.x) + '</b>';
$.each(this.points, function (i, point) {
s += '<br/>Data value : ' + point.y;
});
/* formát 23-04-13 09:34:27 */
return s;
}
},
});
});
});
</script>
In you script:
$array = [];
while($row = mysql_fetch_array($result)){
$date= strtotime($row['cas'])*1000; // timestamp
$values=hexdec($row['data']); // series1
$val=hexdec($row['src']); // series2
$array[0][]=array($date, $values); //output array
$array[1][]=array($date ,$val);
}
You need paste values to appropriate series index. In other words you can prepare your $array() and add point to one of series. To be honest I have no data so It is only concept.