Related
I want to add two moving points represent the location of two trains according to the day. My day data is as shown in pic starting from 0 to 7. However, in the resulting animation, the slider does not slide into the integer day. It jumped from 1.75 to 2.25 or 2.75 to 3.25 automatically. Can anyone help me to solve that?
trainpath info
import plotly.graph_objects as go
import pandas as pd
dataset = pd.read_csv('trainpath.csv')
days = []
for k in range(len(dataset['day'])):
if dataset['day'][k] not in days:
days.append(dataset['day'][k])
t1 = [-1, 0, 1, 1, 1, 0, -1, -1, -1]
k1 = [-20, -20, -20, 0, 20, 20, 20, 0, -20]
# make list of trains
trains = []
for train in dataset["train"]:
if train not in trains:
trains.append(train)
# make figure
fig_dict = {
"data": [go.Scatter(x=t1, y=k1,
mode="lines",
line=dict(width=2, color="blue")),
go.Scatter(x=t1, y=k1,
mode="lines",
line=dict(width=2, color="blue"))],
"layout": {},
"frames": []
}
# fill in most of layout
fig_dict['layout']['title'] = {'text':'Train Animation'}
fig_dict["layout"]["xaxis"] = {"range": [-10, 10], "title": "xlocation", 'autorange':False, 'zeroline':False}
fig_dict["layout"]["yaxis"] = {"range": [-22, 22], "title": "ylocation", 'autorange':False, 'zeroline':False}
fig_dict["layout"]["hovermode"] = "closest"
fig_dict["layout"]["updatemenus"] = [
{
"buttons": [
{
"args": [None, {"frame": {"duration": 500, "redraw": False},
"fromcurrent": True, "transition": {"duration": 300,
"easing": "quadratic-in-out"}}],
"label": "Play",
"method": "animate"
},
{
"args": [[None], {"frame": {"duration": 0, "redraw": False},
"mode": "immediate",
"transition": {"duration": 0}}],
"label": "Pause",
"method": "animate"
}
],
"direction": "left",
"pad": {"r": 10, "t": 87},
"showactive": False,
"type": "buttons",
"x": 0.1,
"xanchor": "right",
"y": 0,
"yanchor": "top"
}
]
sliders_dict = {
"active": 0,
"yanchor": "top",
"xanchor": "left",
"currentvalue": {
"font": {"size": 20},
"prefix": "Day:",
"visible": True,
"xanchor": "right"
},
"transition": {"duration": 300, "easing": "cubic-in-out"},
"pad": {"b": 10, "t": 50},
"len": 0.9,
"x": 0.1,
"y": 0,
"steps": []
}
# make data
day = 0
for train in trains:
dataset_by_date = dataset[dataset['day']==day]
dataset_by_date_and_train = dataset_by_date[dataset_by_date['train']==train]
data_dict = {
'x': list(dataset_by_date_and_train['x']),
'y': list(dataset_by_date_and_train['y']),
'mode': 'markers',
'text': train,
'marker': {
'sizemode': 'area',
'sizeref': 20,
'size': 20,
# 'size': list(dataset_by_date_and_train['quantity']) # this section can be used to increase or decrease the marker size to reflect the material quantity
},
'name': train
}
fig_dict['data'].append(data_dict)
# make frames
for day in days:
frame={'data': [go.Scatter(x=t1, y=k1,
mode="lines",
line=dict(width=2, color="blue")),
go.Scatter(x=t1, y=k1,
mode="lines",
line=dict(width=2, color="blue"))], 'name':str(day)}
for train in trains:
dataset_by_date = dataset[dataset['day'] == day]
dataset_by_date_and_train = dataset_by_date[dataset_by_date['train'] == train]
data_dict = {
'x': list(dataset_by_date_and_train['x']),
'y': list(dataset_by_date_and_train['y']),
'mode': 'markers',
'text': train,
'marker': {
'sizemode': 'area',
'sizeref': 20,
'size': 20,
# 'size': list(dataset_by_date_and_train['quantity']) # this section can be used to increase or decrease the marker size to reflect the material quantity
},
'name': train
}
frame['data'].append(data_dict)
fig_dict['frames'].append(frame)
slider_step = {'args': [
[day],
{'frame': {'duration':300, 'redraw':False},
'mode': 'immediate',
'transition': {'duration':3000}}
],
'label': day,
'method': 'animate'}
sliders_dict["steps"].append(slider_step)
if day == 7:
print('H')
fig_dict["layout"]["sliders"] = [sliders_dict]
fig = go.Figure(fig_dict)
fig.show()
I am using multi-select to filter out data.
<Multiselect
v-model="roles"
class="input1"
placeholder="Select Roles"
mode="tags"
:searchable="true"
:options="roleOptions"
/>
<Multiselect
v-model="sub_organization"
class="input1"
placeholder="Select sub-organization"
mode="tags"
:searchable="true"
:options="suborgOptions"
/>
data:() => ({
mode: "tags",
closeOnSelect: false,
roleOptions: [],
suborgOptions: [],
searchable: true,
sub_organization: [],
roles: [],
filteredData: [],
fetchedData: [],
}),
searchResult() {
this.filteredData = this.fetchedData.filter((data) => {
// var intRoles = parseInt(data.roles.split(", "))
// var intSuborgs = parseInt(data.suborgs.split(", "))
return (
// intSuborgs == this.sub_organization &&
// intRoles == this.roles
data.suborgs.includes(this.sub_organization) &&
data.roles.includes(this.roles)
);
});
},
data.roles = {1, 3},
{1, 4, 5, 7},
{10, 14},
{1, 9},
{2, 4, 6, 8},
{4, 5},
{4, 10},
{9, 1, 4}
for example:
when I use includes and I searched 1 it returns all data.roles with 1 in it including 10, 14, 4, 10 etc.
using includes():
searching 1 returns {1, 3}, {1, 4, 5, 7}, {10, 14}, {1, 9}, {4, 10}, {9, 1, 4}
searching 4 returns {1, 4, 5, 7}, {10, 14}, {4, 10}, {9, 1, 4}, {4, 5}, {2, 4, 6, 8}
as you can see I commented out intRoles and intSuborgs, I tried using parseInt and then split it, when I search 1 it returns only the objects that have 1 in index 0
using parseInt and split:
searching 1 returns {1, 3}, {1, 4, 5, 7}, {1, 9}
searching 4 returns {4, 5}, {4, 10},
What I want to happen is when I search 1 it would return only the objects that has 1 in it excluding double digits with 1, or since I am using multi-select searching 1 and 4 returns objects with 1 and 4 in it excluding double digits with 1 and 4 also.
I use the Google AdWords API to collect information about the search volume for a specific keyword. But the data I get as a response doesn't match with the data from the keyword planner or other keyword tools. Here I check the search volume for the keyword "Hunde" in Berlin, Germany in german.
targeting_service = adwordsClient.GetService('TargetingIdeaService')
selector = {'ideaType': 'KEYWORD', 'requestType' : 'STATS'}
selector['requestedAttributeTypes'] = ['KEYWORD_TEXT', 'SEARCH_VOLUME', 'TARGETED_MONTHLY_SEARCHES']
offset = 0
selector['paging'] = {'startIndex' : str(offset), 'numberResults' : str(1)}
selector['searchParameters'] = [{
'xsi_type': 'RelatedToQuerySearchParameter',
'queries': ["hunde"]
}]
selector['searchParameters'].append({
'xsi_type': 'LocationSearchParameter',
'locations': [{'id': '1003854'}]
})
selector['searchParameters'].append({
'xsi_type': 'LanguageSearchParameter',
'languages': [{'id': '1001'}]
})
page = targeting_service.get(selector)
print(page)
As a response I get:
{
'totalNumEntries': 1,
'entries': [
{
'data': [
{
'key': 'KEYWORD_TEXT',
'value': {
'Attribute.Type': 'StringAttribute',
'value': 'hunde'
}
},
{
'key': 'TARGETED_MONTHLY_SEARCHES',
'value': {
'Attribute.Type': 'MonthlySearchVolumeAttribute',
'value': [
{
'year': 2020,
'month': 12,
'count': 4743382
},
{
'year': 2020,
'month': 11,
'count': 455583
},
{
'year': 2020,
'month': 10,
'count': 8797951
},
{
'year': 2020,
'month': 9,
'count': 5218694
},
{
'year': 2020,
'month': 8,
'count': 5089585
},
{
'year': 2020,
'month': 7,
'count': 3149591
},
{
'year': 2020,
'month': 6,
'count': 3020638
},
{
'year': 2020,
'month': 5,
'count': 4928527
},
{
'year': 2020,
'month': 4,
'count': 754959
},
{
'year': 2020,
'month': 3,
'count': 5649676
},
{
'year': 2020,
'month': 2,
'count': 1590789
},
{
'year': 2020,
'month': 1,
'count': 2506674
}
]
}
},
{
'key': 'SEARCH_VOLUME',
'value': {
'Attribute.Type': 'LongAttribute',
'value': 3825504
}
}
]
}
]
}
But this data doesn't match with the data from the keyword planer.
Avg. monthly searches (Keyword planner): 10K – 100K
Does somebody knows why the data I'm receiving is wrong?
These questions pop up somewhat frequently and are generally not easy to answer. Did you make sure that the specified searchParameters in your request correspond exactly to what you are using in the Keyword Planner?
Additionally, you could check out the KeywordPlanService of the newer Ads API. According to this post by a Google Ads API advisor, it should be closer to what you can do in the web UI than the Adwords API's TargetingIdeaService.
If OP didn't figure it out, i've had the same headaches.
I solved this when adding NetworkSearchParameter to [searchparameter] so the API only returns google data.
my code after adding in the additional argument.
selector['searchParameters'] = [{
'xsi_type' : 'RelatedToQuerySearchParameter',
'queries' : sublist,
},
{
'xsi_type':'LocationSearchParameter',
'locations' : [country_ids[country]],
},
{
'xsi_type': 'NetworkSearchParameter',
'networkSetting': {
'targetGoogleSearch': True,
'targetSearchNetwork': False,
'targetContentNetwork': False,
'targetPartnerSearchNetwork': False
}}]
I'm building a rally custom HTML app. I would like to create a heat map chart. How can I do that?
I've tried to create Rally Chart of the type 'heatmap' (code below). As a result, I see the 404 error message in the console:
GET https://rally1.rallydev.com/slm/panel/highcharts/heatmap.js?_dc=1558434971290 404
When I try to use Highcharts library directly I'm getting a conflict with https://rally1.rallydev.com/apps/2.1/lib/analytics/analytics-all.js - highcharts being loaded twice. As a result analytics lib do not load I guess and I get an error like Lumenize.Time undefined.
this.chart = this.add(
Ext.create('Rally.ui.chart.Chart', {
loadMask: false,
chartData: {
series: [{
type:'heatmap',
name: 'Sales per employee',
borderWidth: 1,
data: [[0, 0, 10], [0, 1, 19], [0, 2, 8], [0, 3, 24], [0, 4, 67], [1, 0, 92], [1, 1, 58], [1, 2, 78], [1, 3, 117], [1, 4, 48], [2, 0, 35], [2, 1, 15], [2, 2, 123], [2, 3, 64], [2, 4, 52], [3, 0, 72], [3, 1, 132], [3, 2, 114], [3, 3, 19], [3, 4, 16], [4, 0, 38], [4, 1, 5], [4, 2, 8], [4, 3, 117], [4, 4, 115], [5, 0, 88], [5, 1, 32], [5, 2, 12], [5, 3, 6], [5, 4, 120], [6, 0, 13], [6, 1, 44], [6, 2, 88], [6, 3, 98], [6, 4, 96], [7, 0, 31], [7, 1, 1], [7, 2, 82], [7, 3, 32], [7, 4, 30], [8, 0, 85], [8, 1, 97], [8, 2, 123], [8, 3, 64], [8, 4, 84], [9, 0, 47], [9, 1, 114], [9, 2, 31], [9, 3, 48], [9, 4, 91]],
dataLabels: {
enabled: true,
color: '#000000'
}
}]
},
chartConfig: {
chart: {
marginTop: 40,
marginBottom: 80,
plotBorderWidth: 1
},
title: {
text: 'Sales per employee per weekday'
},
xAxis: {
categories: ['Alexander', 'Marie', 'Maximilian', 'Sophia', 'Lukas', 'Maria', 'Leon', 'Anna', 'Tim', 'Laura']
},
yAxis: {
categories: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
title: null
},
colorAxis: {
min: 0,
minColor: '#FFFFFF',
//maxColor: Highcharts.getOptions().colors[0]
},
legend: {
align: 'right',
layout: 'vertical',
margin: 0,
verticalAlign: 'top',
y: 25,
symbolHeight: 280
},
tooltip: {
formatter: function () {
return '<b>' + this.series.xAxis.categories[this.point.x] + '</b> sold <br><b>' +
this.point.value + '</b> items on <br><b>' + this.series.yAxis.categories[this.point.y] + '</b>';
}
},
}
})
);
The problem you are going to hit is that the Highcharts v3.0.10 is bundled into the analytics code. This has been done so that there is a known Highcharts library used with the added Lumenize code - i.e. they match. The analytics library is dynamically loaded if the SDK can't find a Highcharts library as it starts up (i.e. window.Highcharts is undefined).
The result of this is that it looks like it is quite kludgy to change the Highcharts arrangement to add heatmaps. Someone who is better at javascript library loading/overloading might have a different view. You would have to load the heatmap.js file into your app after the app has started (in 'launch'?) to get around the dynamic loading.
I know that this is not directly related to your Highcharts question, but if it is just a 'heatmap' you are after, not necessarily a Highcharts heatmap, I have started to use d3 to visualise stuff in Rally. There is a d3 heatmap example here if you are interested: http://bl.ocks.org/tjdecke/5558084
I have done a bit of work to get d3 working inside a Rally custom app. There are a few examples on my github, but have a look here: https://github.com/nikantonelli/Radial-Density
I have simple bar chart like this:
Here is my C3JS
var chart = c3.generate({
data: {
json:[{"A": 67, "B": 10, "site": "Google", "C": 12}, {"A": 10, "B": 20, "site": "Amazon", "C": 12}, {"A": 25, "B": 10, "site": "Stackoverflow", "C": 8}, {"A": 20, "B": 22, "site": "Yahoo", "C": 12}, {"A": 76, "B": 30, "site": "eBay", "C": 9}],
mimeType: 'json',
keys: {
x: 'site',
value: ['A','B','C']
},
type: 'bar',
selection: {
enabled: true
},
onselected: function(d,element)
{
alert('selected x: '+chart.selected()[0].x+' value: '+chart.selected()[0].value+' name: '+chart.selected()[0].name);
},
groups: [
['A','B','C']
]
},
axis: {
x: {
type: 'category'
}
}
});
After some chart elemnt is selected (clicked), alert shows X and Value and Name attributes of first selected element. For example "selected x: 0 value: 67 name: A" after I click on left-top chart element. How can I get value shown on X axis? In this case it is "Google".
Property categories is populated when the x-axis is declared to be of type category as it is in this case. So to get the data from the x-axis you needs to call the .categories() function.
onselected: function(d,element){alert(chart.categories()[d.index]);}
https://jsfiddle.net/4bos2qzx/1/