Fill area below a dashed line - flot

Right now I have the following data:
[{
data : [[3, 4], [6, 5]],
lines : { show : true, fill : true, steps : true },
dashes: { show: true, lineWidth: 1 },
color : 'red',
label : 'Data series'
}]
If I change lines.show to false then the area below the line does not get filled. dashes does not have a show property.
Is it possible to fill the area below a dotted line?

I found a solution: Show the line and set its width to 0.
lines : { show : true, lineWidth : 0}

Related

Need help to figure out how to update a key.value in some list of python dictionaries

Hi guys I have this data:
members = [{'n1': 1, 'active': True, 'ticket': 10, },
{'n2': 2, 'active': False, 'ticket': 0, },
{'n3': 3, 'active': True, 'ticket': 12, }]
I need to update the members time to time, to check if they are active or not, and give new tickets to active members and maybe filtering the inactive ones.
For checking actives or inactive I can use some like this:
inactive = list(filter(lambda n: n.get('active') == False, members))
Or maybe keep the inactive but not give them new tickets.
The updates are user inputs for n and tickets.
So i need to check if the inputs are already in the dict just to update the data needed, ie. If users input 1 for n I just have 1 already so I just update ticket. Else i update both.
But I got a lil stucked in how could I check if the the number I will input in n is already in the dict inside the list.
For new members I can use some like this:
updated = {'n': int(input('number'), 'active': True, 'ticket': int(input('number')}
So in summary:
I need to check if n.value is in the dict, if so update only the ['ticket].value or if not update the dict with n and ticket new values.
Paulo
>>> members = [{'n': 1, 'active': True, 'ticket': 10, },
... {'n': 2, 'active': False, 'ticket': 0, },
... {'n': 3, 'active': True, 'ticket': 12, }]
To find a member, you just have to iterate over the members until you find the good one:
>>> def find_member(k):
... return next(((i, m) for i, m in enumerate(members) if m['n'] == k), (-1, None))
The next function will return the first found member whose key 'n' has the value k, or Npne if there is none.
I added an index if you need to remove a member by name.
>>> find_member(2)
(1, {'n': 2, 'active': False, 'ticket': 0})
>>> find_member(10)
(-1, None)
To update a member, use this function and do the update:
>>> def update_member(k, t):
... i, m = find_member(k)
... if i == -1:
... members.append({'n': k, 'active': True, 'ticket': t})
... else:
... m.update({'ticket': t})
>>> update_member(1, 15)
>>> members
[{'n': 1, 'active': True, 'ticket': 15}, {'n': 2, 'active': False, 'ticket': 0}, {'n': 3, 'active': True, 'ticket': 12}]
My advice is: create a class Member that wraps the dict and provides some useful methods (set_active, renew_ticket, ...) and a class Members that wraps the list and provides other useful methods (find_by_name, update_by_name, delete_by_name, ...)

how to set zoom range for time ("%H:%M") in flot chart?

i have to set min and max zoom range for time. for example 00:00 to 23:00.
xaxis: {
mode: "time",
font: { color: "black"},
timezone: "browser",
timeformat :"%H:%M",
labelWidth: 30,
zoomRange: [0, 0]
}

plotly python - fix colours for specific legend labels

I am making a pie chart that looks like this.
I want to make multiple pie charts for different sets of data and keep the colours fixed to the legend names, but when the order changes, the colour scheme follows the order.
Is there a way to pass a dict into the chart to fix the colours to specific items?
[]
You cannot pass a dictionary with your colors, but you can specify the colors manually, set sort to False and pass the values always in the same order, e.g.
import plotly
fig = {
'data': [{'labels': ['Residential', 'Non-Residential', 'Utility'],
'values': [19, 26, 55],
'type': 'pie',
'sort': False,
'marker': {'colors': ['rgb(255, 0, 0)',
'rgb(0, 255, 0)',
'rgb(0, 0, 255)']
}
}]
}
fig = {
'data': [{'labels': ['Residential', 'Non-Residential', 'Utility'],
'values': [100, 10, 25],
'type': 'pie',
'sort': False,
'marker': {'colors': ['rgb(255, 0, 0)',
'rgb(0, 255, 0)',
'rgb(0, 0, 255)']
}
}]
}
plotly.offline.plot(fig)

add colorstop dynamically in fabric.js

I have been working on this for about a week now and I still have no idea of how to DYNAMICALLY add a colorstop to a gradient fill.
I can fill an object with a gradient fill, but how do I add a new colorstop to it after it has been created?
circle.setGradient('fill',
{
type: 'linear',
x1: 0,
y1: -circle.height / 2,
x2: 0,
y2: circle.height / 2,
colorStops:
{
0: '#000',
1: '#f00'
}
});
canvas.add(circle);
Assuming I have the above code, how can I add a third colorStop (e.g. 0.5: 'blue') dynamically, after the fill has been created?
Help?

Is there a way to add some margin between bars in a flot bar chart?

I've got two bars, one for inbound and one for outbound. They look like this:
Is there a way I could add some margin between them? Right now the values for them is
var d1 = [[0, 1], [3, 7], [6, 12], [9, 17]];
var d2 = [[1, 4], [4, 9], [7, 14], [10, 19]];
and as you could see I'm skipping one for each period, but I would also want some margin between :D
Set the barWidth parameter (in the bars object inside the series object inside the options object) to something less than 1.
bars: {
show: true,
align: "center",
barWidth: 0.8,
fill: true,
horizontal: true
}

Resources