I am building following chart
https://jsfiddle.net/marialaustsen/x1s9ndm3/11/
I am trying to create a click function for the All button, but instead of hide the other series and show only one serie, I would like to show all series in the chart when clicking the all button. The most scaleable way of doing this is simply to redraw the chart but I cannot figure out how..
This should be super simple...
I have tried to use the redraw method in a click event
$('#all').click(function () {
chart.redraw();
});
All the code here:
`````
<div id="container1"></div>
<button id="All">All</button>
<button id="2017">2017</button>
<button id="2018">2018</button>
<button id="2019">2019</button>
$(function() {
// Apply the grey theme
Highcharts.setOptions( {
colors: ['#2b908f', '#90ee7e', '#f45b5b', '#7798BF', '#aaeeee', '#ff0066', '#eeaaee', '
#55BF3B', '#DF5353', '#7798BF', '#aaeeee'], chart: {
backgroundColor: {
linearGradient: {
x1: 0, y1: 0, x2: 1, y2: 1
}
, stops: [ [0, '#f5f5f5'], [1, '#F0F0F0']]
}
, style: {
fontFamily: 'Montserrat'
}
, plotBorderColor: '#000066'
}
, title: {
style: {
color: '#00BFB3', textTransform: 'uppercase', fontSize: '20px'
}
}
, subtitle: {
style: {
color: '#007396', textTransform: 'uppercase'
}
}
, xAxis: {
gridLineColor: '#B5B5B9', labels: {
style: {
color: '#007396'
}
}
, lineColor: '#B5B5B9', minorGridLineColor: '#505053', tickColor: '#B5B5B9', title: {
style: {
color: '#007396'
}
}
}
, yAxis: {
gridLineColor: '#B5B5B9', labels: {
style: {
color: '#00BFB3'
}
}
, lineColor: '#B5B5B9', minorGridLineColor: '#505053', tickColor: '#B5B5B9', tickWidth: 1, title: {
style: {
color: '#007396'
}
}
}
, tooltip: {
backgroundColor: 'rgba(0, 0, 0, 0.85)', style: {
color: '#F0F0F0'
}
}
, plotOptions: {
series: {
dataLabels: {
color: '#007396', style: {
fontSize: '13px'
}
}
, marker: {
lineColor: '#333'
}
}
, boxplot: {
fillColor: '#505053'
}
, candlestick: {
lineColor: 'white'
}
, errorbar: {
color: 'white'
}
}
, legend: {
backgroundColor: 'rgba(62,62,62,1)', itemStyle: {
color: '#E0E0E3'
}
, itemHoverStyle: {
color: '#FFF'
}
, itemHiddenStyle: {
color: '#606063'
}
, title: {
style: {
color: '#C0C0C0'
}
}
}
, credits: {
style: {
color: '#666'
}
}
, labels: {
style: {
color: '#707073'
}
}
, drilldown: {
activeAxisLabelStyle: {
color: '#007396'
}
, activeDataLabelStyle: {
color: '#007396'
}
}
, navigation: {
buttonOptions: {
symbolStroke: '#DDDDDD', theme: {
fill: '#505053'
}
}
}
, // scroll charts
rangeSelector: {
buttonTheme: {
fill: '#505053', stroke: '#000000', style: {
color: '#CCC'
}
, states: {
hover: {
fill: '#707073', stroke: '#000000', style: {
color: 'white'
}
}
, select: {
fill: '#000003', stroke: '#000000', style: {
color: 'white'
}
}
}
}
, inputBoxBorderColor: '#505053', inputStyle: {
backgroundColor: '#333', color: 'silver'
}
, labelStyle: {
color: 'silver'
}
}
, navigator: {
handles: {
backgroundColor: '#666', borderColor: '#AAA'
}
, outlineColor: '#CCC', maskFill: 'rgba(255,255,255,0.1)', series: {
color: '#7798BF', lineColor: '#A6C7ED'
}
, xAxis: {
gridLineColor: '#505053'
}
}
, scrollbar: {
barBackgroundColor: '#808083', barBorderColor: '#808083', buttonArrowColor: '#CCC',
buttonBackgroundColor: '#606063', buttonBorderColor: '#606063', rifleColor: '#FFF',
trackBackgroundColor: '#404043', trackBorderColor: '#404043'
}
});
// Create the chart
Highcharts.chart('container1', {
chart: {
type: 'column'
},
title: {
text: 'Feedback per quarter grouped by year'
},
subtitle: {
text: 'Source: '
},
xAxis: {
categories: [
'Q1',
'Q2',
'Q3',
'Q4'
],
crosshair: true
},
yAxis: {
min: 0,
title: {
text: 'Total'
}
},
tooltip: {
headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
'<td style="padding:0"><b>{point.y} feedback</b></td></tr>',
footerFormat: '</table>',
shared: true,
useHTML: true
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: [{
name: '2017',
data: [55, 72, 108, 130]
}, {
name: '2018',
data: [80, 65, 100, 40]
}, {
name: '2019',
data: [45, 34, 67, 24]
}]
}, function(chart) {
// the button action
$('#all').click(function () {
chart.redraw()
})
$('#2017').click(function() {
Highcharts.each(chart.series, function(p, i) {
p.name.includes('2017') ? p.show() : p.hide()
})
})
$('#2018').click(function() {
Highcharts.each(chart.series, function(p, i) {
p.name.includes('2018') ? p.show() : p.hide()
})
})
$('#2019').click(function() {
Highcharts.each(chart.series, function(p, i) {
p.name.includes('2019') ? p.show() : p.hide()
})
})
});
});
How do I redraw or reload the chart onclick the All button?
You need to show series and redraw a chart. The most efficient way is to use the setVisible method on each series with redraw argument set to false and call chart.redraw() outside the loop.
$('#All').click(function() {
Highcharts.each(chart.series, function(s, i) {
s.setVisible(true, false);
});
chart.redraw();
});
Live demo: https://jsfiddle.net/BlackLabel/eztvoqa4/
API Reference:
https://api.highcharts.com/class-reference/Highcharts.Chart#redraw
https://api.highcharts.com/class-reference/Highcharts.Series#setVisible
Related
I have the following:
<div class="flex flex-row items-center justify-start flex-nowrap space-x-6">
<div>hello</div>
<div>world</div>
</div>
Now the there is no space-x-6 applied between the items. However when I try this in the Tailwind playground it works. Any ideas?
tailwind.config.js:
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {
animation: {
blob: 'blob 7s infinite',
},
keyframes: {
blob: {
'0%': {
transform: 'translate(0px, 0px) scale(1)',
},
'33%': {
transform: 'translate(30px, -50px) scale(1.1)',
},
'66%': {
transform: 'translate(-20px, 20px) scale(0.9)',
},
'100%': {
transform: 'tranlate(0px, 0px) scale(1)',
},
},
},
fontFamily: {
sans: ['Inter', ...defaultTheme.fontFamily.sans],
mono: ['iAWriter Mono', ...defaultTheme.fontFamily.mono],
},
boxShadow: {
card: '0 0 0.5rem rgba(0, 0, 0, 0.075)',
},
typography: (theme) => ({
DEFAULT: {
css: {
whiteSpace: 'pre-wrap',
figcaption: {
textAlign: 'center',
},
strong: {
fontWeight: theme('fontWeight.medium'),
},
// Image margin is handled by `figure`
img: {
marginTop: null,
marginBottom: null,
borderRadius: theme('borderRadius.lg'),
},
blockquote: {
borderLeftWidth: '2px',
fontStyle: null,
fontWeight: theme('fontWeight.normal'),
borderColor: theme('colors.blue.600'),
},
hr: {
borderTopWidth: '2px',
maxWidth: '12rem',
marginLeft: 'auto',
marginRight: 'auto',
},
'blockquote p:first-of-type::before, blockquote p:last-of-type::after': {
content: 'unset !important',
},
a: {
color: theme('colors.blue.600'),
wordWrap: 'break-word',
fontWeight: theme('fontWeight.normal'),
textDecoration: 'none',
textUnderlineOffset: '0.2em',
'&:hover': {
textDecoration: 'underline',
},
},
'ol > li::before': {
fontFamily: theme('fontFamily.mono').join(', '),
color: theme('colors.gray.400'),
},
'ul > li::before': {
backgroundColor: theme('colors.gray.400'),
},
'.twitter-tweet': {
marginLeft: 'auto',
marginRight: 'auto',
},
code: {
fontWeight: theme('fontWeight.normal'),
background: theme('colors.gray.200'),
color: theme('colors.gray.600'),
borderRadius: theme('borderRadius.lg'),
padding: `0.125rem ${theme('padding.1')}`,
'&::before, &::after': {
content: 'unset !important',
},
},
'[data-nft] *, .opengraph *, .opengraph *:hover': {
margin: '0',
textDecoration: 'none',
borderRadius: 'unset',
},
},
},
lg: {
css: {
'ol > li, ul > li': {
marginTop: '0',
marginBottom: '0',
},
// Image margin is handled by `figure`
img: {
marginTop: null,
marginBottom: null,
},
},
},
}),
},
},
plugins: [require('#tailwindcss/typography'), require('#tailwindcss/line-clamp'), require('#tailwindcss/forms')],
};
UPDATE:
So for the space-x-# class I do a little fancyness:
export function getSpacing(spacing, direction) {
const spacingTailwindClasses = [];
if (typeof direction === 'string') {
spacingTailwindClasses.push(getTailwindSpacingClassname(spacing, direction));
} else {
spacingTailwindClasses.push(getTailwindSpacingClassname(spacing, direction.sOnly || direction.sUp));
if (direction.sUp) {
spacingTailwindClasses.push(`sm:${getTailwindSpacingClassname(spacing, direction.sUp)}`);
if (direction.sOnly) {
spacingTailwindClasses.push(`sm:${getTailwindSpacingClassname('none', direction.sOnly)}`);
}
}
}
const spacingObject = {};
const classes = spacingTailwindClasses.join(' ');
spacingObject[classes] = true;
return spacingObject;
}
I'm using Material UI with React for the first time. I want to change my global theme, but what I want to change has two classes:
.MuiListItem-root.Mui-selected, .MuiListItem-root.Mui-selected:hover {
background-color: rgba(0, 0, 0, 0.08);
}
How can I select them with createMuiTheme? I've tried this:
createMuiTheme({
overrides: {
MuiListItem: {
root: {
Mui: {
selected: {
backgroundColor: "black",
"&:hover": {
backgroundColor: "blue",
},
},
},
},
},
}
})
Thank you in advance
Here's the correct syntax:
const theme = createMuiTheme({
overrides: {
MuiListItem: {
root: {
"&.Mui-selected": {
backgroundColor: "black",
"&:hover": {
backgroundColor: "blue"
}
}
}
}
}
});
It is also equivalent to do:
const theme = createMuiTheme({
overrides: {
MuiListItem: {
root: {
"&$selected": {
backgroundColor: "black",
"&:hover": {
backgroundColor: "blue"
}
}
}
}
}
});
Just try this code
createMuiTheme({
overrides: {
MuiListItem: {
root: {
'&$selected': {
backgroundColor: "black"
},
'&$selected:hover'{
backgroundColor: "blue"
}
},
},
},
})
and look to this response
Material UI adds the global Mui-selected classes to make it easier to change specific elements globally.
However, you should just be targeting the MuiListItem classes according to the docs like so:
createMuiTheme({
overrides: {
MuiListItem: {
selected: {
backgroundColor: "black",
"&:hover": {
backgroundColor: "blue",
},
},
},
}
})
I see that this doesn't work anymore in the current version of Material UI. In the source code of the ListItem component, it is now defined like so:
root: {
'&$selected, &$selected:hover': {
backgroundColor: theme.palette.action.selected,
},
...
}
I have a chart with daily values of the month of October.
Two buttons: week and month.
Week plotband has to be identical with month plotband: First 2 days are green, next 5 days are blue in month plotband. When selecting week, the range date 1-7 should be same colour green and blue.
Highcharts.chart('container', {
chart: {
type: 'column',
},
title: {
text: 'How long time a TR has been placed in stages longer than 48 hours'
},
legend: {
enabled: true
},
subtitle: {
text: 'Input - verify should max be 48 hours = green zone'
},
data: {
csv: document.getElementById('csv').innerHTML
},
plotOptions: {
column: {
},
series: {
dataLabels: {
enabled: false,
format: '{point.y}'
}
}
},
tooltip: {
},
rangeSelector: {
buttonSpacing: 10,
enabled: true,
inputEnabled: false,
selected: 1,
buttons: [{
type: 'week',
count: 1,
text: 'Week'
}, {
type: 'month',
count: 1,
text: 'Month'
}],
},
xAxis: [{
id: 'one',
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#E8F5E9'
}, {
from: 1538524800000,
to: 1538870400000,
color: '#E0ECEC'
}, {
from: 1538870400000,
to: 1539475200000,
color: "#FFFDE7"
}, {
from: 1539475200000,
to: 1540944000000,
color: "#FFEBEE"
}],
}, {
id: 'two',
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#E8F5E9'
}, {
from: 1538524800000,
to: 1538870400000,
color: '#E0ECEC'
}],
}],
yAxis: {
min: 0,
max: 100,
title: {
text: 'TRADING RECORDS',
}
}
});
Please see jsfiddle
Is there a way to toggle between two xaxis with different plotBands: when clicking on the 'week' button, one plotband will display and when clicking on the 'month' button another plotband will display. So the colours of the plotband is relative to the dates?
I assume I have to use event functions like setExtremes and afterSetExtremes, but not sure how to do it?
Thanks much appreciated for help.
I managed to simulate the output with this function:
events: {
afterSetExtremes: function (e) {
if (e.trigger == "rangeSelectorButton" &&
e.rangeSelectorButton.text == "Week") {
// it is your button that caused this,
// so setExtrememes to your custom
// have to do in timeout to let
// highcharts finish processing events...
setTimeout(function () {
Highcharts.charts[0].xAxis[0].setExtremes(1538352000000, 1538524800000)
}, 1);
}
},
}
But it only work when selecting specific: setExtremes(1538352000000, 1538524800000)
I think a scaleable solution for any 7 days would require some sort of exception functionality for remove current plotband on xaxis with addplotband
Updated fiddle
I added custom buttons instead: https://forum.highcharts.com/viewtopic.php?t=31649
<div class="btn-group" data-toggle="buttons">
<button class="btn btn-custom" id="one">48 hours</button>
<button class="btn btn-custom" id="two">7 days</button>
<button class="btn btn-custom" id="three">14 days</button>
<button class="btn btn-custom" id="four">31 days</button>
<button class="btn btn-custom" id="all">All</button>
</div>
<div id="containerbenchmark"></div>
$.get('bm.csv', function (bmcsv) {
var chart = new Highcharts.Chart({
chart: {
renderTo: 'containerbenchmark',
type: 'areaspline',
},
title: {
text: ''
},
legend: {
enabled: true
},
subtitle: {
text: 'Input - verify - close should max be 48 hours = green zone'
},
data: {
csv: bmcsv,
},
plotOptions: {
areaspline: {
stacking: 'normal'
},
series: {
dataLabels: {
enabled: false,
format: '{point.y}'
}
}
},
tooltip: {
/*headerFormat: '<span style="font-size: 16px">{point.key}</span><br/>',
pointFormat: '<span style="font-size: 14px; color:{series.color}">{series.name}: <span style="font-size: 14px">{point.y} {point.total}</span><br/>',
footerFormat: '<span style="font-size: 16px">{point.total}</span><br/>',*/
shared: true,
useHTML: true,
formatter: function () {
var tooltip = '<table><span style="font-size: 16px">' + Highcharts.dateFormat('%e/%b/%Y',
new Date(this.x)) + '</span><br/><tbody>';
//loop each point in this.points
$.each(this.points, function (i, point) {
tooltip += '<tr><th style="font-size: 14px; color: ' + point.series.color + '">' + point.series.name + ': </th>' +
'<td style="font-size: 14px; text-align: right">' + point.y + '</td></tr>'
});
tooltip += '<tr><th style="font-size: 16px">Total: </th>' +
'<td style="font-size: 16px; text-align:right"><span>' + this.points[0].total + '</span></td></tr>' +
'</tbody></table>';
return tooltip;
}
},
rangeSelector: {
selected: 2,
enabled: true,
inputEnabled: true,
inputDateFormat: "%m/%d/%Y",
inputEditDateFormat: "%m/%d/%Y",
inputDateParser: function (s) {
return Date.UTC(
parseInt(s.substr(6, 4)),
parseInt(s.substr(0, 2) - 1),
parseInt(s.substr(3, 2)),
12
)
}
},
navigator: {
enabled: true
},
xAxis: {
type: 'datetime',
dateTimeLabelFormats: {
millisecond: '%H:%M:%S.%L',
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b \'%y',
year: '%Y'
},
plotBands: [{
from: 1538352000000,
to: 1538524800000,
color: '#cae8cc',
label: {
text: '> 48 hours',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1538524800000,
to: 1538870400000,
color: '#d0e2e2',
label: {
text: '> 7 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1538870400000,
to: 1539475200000,
color: "#fff9b3",
label: {
text: '> 14 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}, {
from: 1539475200000,
to: 1540944000000,
color: "#ffb3be",
label: {
text: '> 31 days',
style: {
color: 'black',
fontWeight: 'bold',
textTransform: 'uppercase',
fontSize: '14px'
}
}
}],
},
yAxis: {
min: 0,
title: {
text: 'TRADING RECORDS',
}
}
}, function (chart) {
// apply the date pickers
setTimeout(function () {
var rangeSelector = $('#containerbenchmark input.highcharts-range-selector');
rangeSelector.datepicker({
autoclose: true,
todayHighlight: true
}) /*.datepicker('update', new Date())*/ ;
var inputMin = rangeSelector.filter('[name=min]');
var inputMax = rangeSelector.filter('[name=max]');
inputMin.datepicker().on("changeDate", function (event) {
console.log(inputMin.datepicker("getDate"));
console.log(inputMin.datepicker("getUTCDate"));
});
}, 1000);
});
$('#one').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538352000000,
1538524800000
);
});
$('#two').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538524800000,
1538870400000
);
});
$('#three').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1538870400000,
1539475200000
);
});
$('#four').click(function () {
toggleActiveState(false);
chart.xAxis[0].setExtremes(
1539475200000,
1540944000000
);
});
$('#all').click(function () {
chart.xAxis[0].setExtremes(
event.min,
event.max
);
});
});
I'm trying to customize vAxis gridlines become dash. But, it didn't run very well, everytime I change stroke-dasharray value in css it still blur.
please, is someone know how to change vAxis gridline into dash?
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawBasic);
function drawBasic() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['Mushrooms', 3],
['Onions', 1],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]
]);
var options = {
width:'100%',
focusTarget: 'category',
backgroundColor: 'transparent',
chartArea: {
left: 20,
top: 10,
width: '100%',
height: '70%'
},
bar: {
groupWidth: '70%'
},
hAxis: {
textStyle: {
fontSize: 9,
color:'#929496'
}
},
vAxis: {
baselineColor: '#e6e6e6',
gridlines: {
color: '#e6e6e6',
count: 9
},
textStyle: {
fontSize: 9,
color:'#929496'
}
},
legend: {
position: 'bottom',
textStyle: {
fontSize: 9,
color:'#929496'
}
},
animation: {
duration: 300,
easing: 'out',
startup: true
}
};
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
#chart_div svg > g:nth-child(3) > g:nth-child(2) > g:first-child rect{
fill: none;
stroke-width: 1;
stroke: #ddd;
stroke-dasharray: 5 5;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
I have a problem with calendar,I want to paint special days different color For example
On calendar
03.06.2011 Day--->blue
04.06.2011 day---->red
12.06.2011-04.07.2011 Days ----> yellow
More than one color I want to use selected day
You can use javascript to do that,
Refer to JSFiddle Here
You can add custom special day,
$(document).ready(function () {
$('#calendar').fullCalendar({
theme: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2014-07-04',
editable: true,
events: [{
title: 'All Day Event',
start: '2014-07-01'
}, {
title: 'Long Event',
start: '2014-07-07',
end: '2014-07-10'
}, {
id: 999,
title: 'Repeating Event',
start: '2014-07-09T16:00:00'
}, {
id: 999,
title: 'Repeating Event',
start: '2014-07-16T16:00:00'
}, {
title: 'Meeting',
start: '2014-07-12T10:30:00',
end: '2014-07-12T12:30:00'
}, {
title: 'Lunch',
start: '2014-07-12T12:00:00'
}, {
title: 'Birthday Party',
start: '2014-07-13T07:00:00'
}, {
title: 'Click for Google',
url: 'http://google.com/',
start: '2014-07-28'
}],
eventAfterAllRender: function (view) {
//Use view.intervalStart and view.intervalEnd to find date range of holidays
//Make ajax call to find holidays in range.
var fourthOfJuly = moment('2014-07-04','YYYY-MM-DD');
var holidays = [fourthOfJuly];
var holidayMoment;
for(var i = 0; i < holidays.length; i++) {
holidayMoment = holidays[i];
if (view.name == 'month') {
$("td[data-date=" + holidayMoment.format('YYYY-MM-DD') + "]").addClass('holiday');
} else if (view.name =='agendaWeek') {
var classNames = $("th:contains(' " + holidayMoment.format('M/D') + "')").attr("class");
if (classNames != null) {
var classNamesArray = classNames.split(" ");
for(var i = 0; i < classNamesArray.length; i++) {
if(classNamesArray[i].indexOf('fc-col') > -1) {
$("td." + classNamesArray[i]).addClass('holiday');
break;
}
}
}
} else if (view.name == 'agendaDay') {
if(holidayMoment.format('YYYY-MM-DD') == $('#calendar').fullCalendar('getDate').format('YYYY-MM-DD')) {
$("td.fc-col0").addClass('holiday');
};
}
}
}
});
});
For changing the colour, you can edit background on .holiday in css file
body {
margin: 0;
padding: 50px 0 0 0;
font-family:"Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
font-size: 14px;
}
#calendar {
width: 100%;
}
.holiday {
background: lightgray;
}
Hope it can help you