I was trying to create something like
But I was not able to get the x and y axis tics coming in
I tried something like this to see if the x axis tics are coming
my #data = (
[0, 0, 10],
[0, 1, 10],
[0, 2, 10],
[],
[1, 0, 10],
[1, 1, 5],
[1, 2, 10],
[],
[2, 0, 10],
[2, 1, 1],
[2, 2, 10],
[],
[3, 0, 10],
[3, 1, 0],
[3, 2, 10],
);
my $chart = Chart::Gnuplot->new(
output => "test1.png",
title => "3D plot from arrays of x, y and z coordinates",
xlabel => 'x',
ylabel => 'y',
xtics => {
labels => ['"pi" 3.1416', '"-pi" -3.1416'],
},
);
$chart->set(pm3d => 'map');
$chart->set(palette => 'defined (0 0 0 1, 1 1 1 0, 2 1 0 0)');
my $dataSet = Chart::Gnuplot::DataSet->new(
points => \#data,
);
$chart->plot3d($dataSet);
I am not sure how the dataset should be and how the x and y axis tics should be added
I tested the above with some examples that I got from the internet but was not able to see the result .
Any help to get this like the image would be greatly appreciated
Got one more issue, when tried to get all the values on X and Y axis, the xtics and ytics are not showing fully as in the above image, the one I got seems like this
The dataset is like this
[
0,
1,
'2.66556908091426'
],
[
0,
2,
'4.37897014657203'
],
[
0,
3,
'1.22514023397498'
],
[
0,
4,
'4.53000730040497'
],
[
0,
5,
'3.01982096624856'
],
[
0,
6,
'0.499618756879272'
],
[
0,
7,
'4.84182728928223'
],
[
0,
8,
'1.96005062661005'
],
[
0,
9,
'2.42800730644825'
],
[
0,
10,
'1.86670807696721'
],
[
0,
11,
'1.81614100038358'
],
[
0,
12,
'4.39616981937487'
],
[
0,
13,
'3.35256272447085'
],
[
0,
14,
'3.24814393010016'
],
[
0,
15,
'1.06219230833835'
],
[
0,
16,
'1.12793288928973'
],
[
0,
17,
'3.26476861756371'
],
[
0,
18,
'3.10578946862982'
],
[
0,
19,
'2.93146341009402'
],
[
0,
20,
'1.72192716962012'
],
[
0,
21,
'4.04316953579938'
],
[
0,
22,
'0.32291976646917'
],
[
0,
23,
'4.42019093014144'
],
[
0,
24,
'3.31129513399691'
],
[
0,
25,
'4.561835018284'
],
[
0,
26,
'1.23709783845847'
],
[
0,
27,
'2.65864379090912'
],
[
0,
28,
'2.30212288203429'
],
[
0,
29,
'0.621743568938786'
],
[
0,
30,
'1.80416068716383'
],
[
0,
31,
'2.66465304546164'
],
[
0,
32,
'3.45680173240485'
],
[
0,
33,
'2.70739617274879'
],
[
0,
34,
'1.11428672300967'
],
[
0,
35,
'1.67761705545201'
],
[
0,
36,
'2.74299975084073'
],
[
0,
37,
'1.80397491377351'
],
[
0,
38,
'4.47728976228916'
],
[
0,
39,
'4.68895286431879'
],
[
0,
40,
'0.14021332300036'
],
[
0,
41,
'2.33736192052044'
],
[
0,
42,
'0.177482592020581'
],
[
0,
43,
'4.73906999291613'
],
[
0,
44,
'2.31796437164231'
],
[
0,
45,
'3.99016409499582'
],
[
0,
46,
'3.38293261332254'
],
[
0,
47,
'2.61350773461833'
],
[
0,
48,
'4.73763682658106'
],
[
0,
49,
'0.882213941365624'
],
[
0,
50,
'0.772076148467349'
],
[
0,
51,
'0.211627911950369'
],
[
0,
52,
'0.983901796963771'
],
[
0,
53,
'4.20512536118553'
],
[
0,
54,
'1.23297443353948'
],
[
0,
55,
'3.81554353946163'
],
[
0,
56,
'3.65498488100304'
],
[
0,
57,
'2.57928958709011'
],
[
0,
58,
'2.59561593117475'
],
[
0,
59,
'0.00576648038274286'
],
[
0,
60,
'3.7901264909274'
],
[
0,
61,
'2.01073954816936'
],
[
0,
62,
'4.20235419868604'
],
[
0,
63,
'0.0699755500835941'
],
[
0,
64,
'1.89704728306967'
],
[
0,
65,
'3.60775496050488'
],
[
0,
66,
'0.210700948492715'
],
[
0,
67,
'1.46456716998541'
],
[
0,
68,
'1.17475107720264'
],
[
0,
69,
'3.05671437798837'
],
[
0,
70,
'2.68927795266336'
],
[
0,
71,
'2.51310517387102'
],
[
0,
72,
'2.47339733795219'
],
[
0,
73,
'0.0279383841017911'
],
[
0,
74,
'0.722901884055389'
],
[
0,
75,
'2.87491127698443'
],
[
0,
76,
'4.06219968687022'
],
[
0,
77,
'1.10014911730135'
],
[
0,
78,
'2.12579086549013'
],
[
0,
79,
'0.969934599414497'
],
[
0,
80,
'0.0104263290325335'
],
[
0,
81,
'4.76235946351673'
],
[
0,
82,
'0.790123228138313'
],
[
0,
83,
'0.0974340515172223'
],
[
0,
84,
'2.25078802534153'
],
[
0,
85,
'1.52078958155231'
],
[
0,
86,
'1.81615557330844'
],
[
0,
87,
'4.29625290304719'
],
[
0,
88,
'3.46711963355933'
],
[
0,
89,
'3.9427030133586'
],
[
0,
90,
'0.10345150062939'
],
[
0,
91,
'3.43953703174092'
],
[
0,
92,
'4.31073758997368'
],
[
0,
93,
'2.58639853373042'
],
[
0,
94,
'4.08224212269872'
],
[],
Here is an example of how you can set the axis labels:
use strict;
use warnings;
use Chart::Gnuplot;
my #data = (
[0, 0, 10],
[0, 1, 10],
[0, 2, 10],
[0, 3, 10],
[],
[1, 0, 10],
[1, 1, 5],
[1, 2, 10],
[1, 3, 10],
[],
[2, 0, 10],
[2, 1, 1],
[2, 2, 1],
[2, 3, 10],
[],
[3, 0, 10],
[3, 1, 0],
[3, 2, 5],
[3, 3, 10],
);
my $chart = Chart::Gnuplot->new(
bg => 'white',
pm3d => 'map',
palette => 'defined (0 0 0 1, 1 1 1 0, 2 1 0 0)',
output => "test.png",
title => "3D plot from arrays of x, y and z coordinates",
xlabel => 'x',
ylabel => 'y',
xtics => {
labels => ['"0030" 0', '"0100" 1', '"0130" 2', '"0200" 3'],
rotate => 90,
},
ytics => {
labels => ['"04-Oct" 0', '"03-Oct" 1', '"02-Oct" 2', '"01-Oct" 3'],
},
);
my $dataSet = Chart::Gnuplot::DataSet->new( points => \#data );
$chart->plot3d($dataSet);
Update:
You can create the xtics in a loop like this (given a DataTime $dt):
my #xtics;
for ( my $i=0; $i<($interval_count-1); $i++ ){
$dt->add(minutes => $interval_period);
my $xtic = '"' . $dt->hour . ':' . $dt->minute . '"' . ' ' . $i;
push #xtics, $xtic;
}
Then set the xtics parameter to Chart::Gnuplot->new() like this:
xtics => { labels => \#xtics, rotate => 90, },
Related
We implemented the Google Combo chart with some horizontal labels in place. But somehow its not showing the first label. Does anybody have any insight in why its not working?
Example: https://www.cdfund.com/track-record/rendement/nac.html
Code example:
var data = new google.visualization.DataTable();
data.addColumn('date', 'Time of measurement');
data.addColumn('number', 'Benchmark (50%/50% TSX-V/HUI) ');
data.addColumn('number', 'CDF NAC ');
data.addRows([[new Date(2018, 0, 1),42.09,82.47,],[new Date(2018, 1, 1),42.88,82.47,],[new Date(2018, 2, 1),39.33,78.26,],[new Date(2018, 3, 1),38.96,72.98,],[new Date(2018, 4, 1),38.98,77.62,],[new Date(2018, 5, 1),38.64,79.53,],[new Date(2018, 6, 1),37.46,75.12,],[new Date(2018, 7, 1),35.75,72.28,],[new Date(2018, 8, 1),33.72,69.29,],[new Date(2018, 9, 1),33.10,71.27,],[new Date(2018, 10, 1),31.72,68.62,],[new Date(2018, 11, 1),30.54,65.53,],[new Date(2019, 0, 1),31.49,61.23,],[new Date(2019, 1, 1),34.30,64.15,],[new Date(2019, 2, 1),34.11,64.13,],[new Date(2019, 3, 1),34.37,63.52,],[new Date(2019, 4, 1),32.61,58.88,],[new Date(2019, 5, 1),32.38,56.60,],[new Date(2019, 6, 1),35.77,59.77,],[new Date(2019, 7, 1),36.44,62.15,],[new Date(2019, 8, 1),39.01,65.34,],[new Date(2019, 9, 1),35.86,61.54,],[new Date(2019, 10, 1),36.70,60.51,],[new Date(2019, 11, 1),36.03,59.00,],[new Date(2020, 0, 1),39.85,67.53,],[new Date(2020, 1, 1),39.15,66.76,],[new Date(2020, 2, 1),34.93,59.35,],[new Date(2020, 3, 1),28.78,50.16,],[new Date(2020, 4, 1),38.07,69.69,],[new Date(2020, 5, 1),41.80,79.14,],[new Date(2020, 6, 1),45.95,91.51,],[new Date(2020, 7, 1),54.05,104.16,],[new Date(2020, 8, 1),55.26,116.85,],[new Date(2020, 9, 1),51.67,115.98,],[new Date(2020, 10, 1),49.87,111.20,],[new Date(2020, 11, 1),49.84,113.11,],[new Date(2021, 0, 1),55.39,125.83,],[new Date(2021, 1, 1),55.39,117.29,],[new Date(2021, 2, 1),56.02,116.46,],[new Date(2021, 3, 1),54.85,113.09,],[new Date(2021, 4, 1),55.98,123.36,],[new Date(2021, 5, 1),60.81,133.58,],[new Date(2021, 6, 1),55.63,120.68,],[new Date(2021, 7, 1),55.32,118.26,],[new Date(2021, 8, 1),52.44,111.19,],[new Date(2021, 9, 1),48.82,102.59,],[new Date(2021, 10, 1),53.49,113.06,],[new Date(2021, 11, 1),53.79,109.98,],[new Date(2022, 0, 1),54.24,114.31,],[new Date(2022, 1, 1),50.69,106.74,],[new Date(2022, 2, 1),53.79,112.16,],[new Date(2022, 3, 1),58.19,118.96,],[new Date(2022, 4, 1),52.91,113.69,],[new Date(2022, 5, 1),47.26,102.92,],[new Date(2022, 6, 1),40.73,86.32,],[new Date(2022, 7, 1),40.44,95.37,],[new Date(2022, 8, 1),38.20,92.43,],[new Date(2022, 9, 1),37.64,81.94,],[new Date(2022, 10, 1),37.82,81.27,],[new Date(2022, 11, 1),,,]]);
var options = {
hAxis: {
format: 'yyyy',
gridlines: { count: 5, color: 'transparent' },
ticks: [new Date(2018, 3, 1), new Date(2019, 1, 1), new Date(2020, 1, 1), new Date(2021, 1, 1), new Date(2022, 1, 1)],
minorGridlines: { color: 'transparent' },
textStyle: { color: '#000', fontSize: 8 }
},
vAxis: {
minorGridlines: { color: 'transparent' },
gridlines: { count: 4 },
textStyle: { color: '#706345', italic: true, fontSize: 8 },
textPosition: 'in',
},
height: '360',
colors: ['#CB9B01','#AA9870','#C2AE81','#706345','#E2D7BD'],
backgroundColor: '#F4F3F0',
chartArea: { 'width': '90%', 'height': '65%' },
legend: { 'position': 'bottom', padding: 30 },
seriesType: 'area',
series: { 1: { type: 'line' }, 2: { type: 'line' }, 3: { type: 'line' }, 4: { type: 'line' }, 5: { type: 'line' } }
};
Thanks
I have the weekly avg from last 5 years, last year, and the year to date.
I would like to show them in a line graph, but showing the respective months in the xaxis...
for example and based on this year:
January has 4 weeks, so xaxis shows jan and there are 4 marks in the chart representing weeks 1,2,3 and 4;
February also has 4 weeks, so xaxis shows feb and there are 3 marks in the chart representing week 5,6,7 and 8;
and so on;
i'm using:
VueJs: 2.6.10
Echarts: 4.9.0
here is my code:
// var motnhNames = [
// 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
// 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
// ]
var monthNames = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52
]
var options = {
title: {
text: 'My data'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['5 Years', 'Last Year', 'YTD']
},
toolbox: {
show: true,
feature: {
dataZoom: {
yAxisIndex: 'none'
},
dataView: {
readOnly: false
},
magicType: {
type: ['line', 'bar']
},
restore: {},
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: monthNames
},
yAxis: {
type: 'value',
},
series: [{
name: '5 Years',
type: 'line',
data: [
19, 46, 34, 33, 16, 3, 6, 33, 20,
25, 5, 29, 48, 36, 1, 28, 48, 1,
34, 22, 50, 38, 11, 11, 37, 11, 28,
15, 14, 5, 7, 2, 46, 3, 12, 10,
20, 50, 39, 17, 50, 7, 27, 6, 5,
11, 35, 25, 50, 18, 40, 30, 35
],
lineStyle: {
type: 'dashed',
width: 5
}
},
{
name: 'Last Year',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46, 41
],
lineStyle: {
type: 'dotted',
width: 5
}
},
{
name: 'YTD',
type: 'line',
data: [
17, 48, 30, 6, 29, 27, 8, 50, 28,
34, 38, 48, 28, 41, 24, 27, 15, 17,
13, 50, 9, 15, 18, 41, 43, 49, 19,
1, 22, 20, 27, 1, 18, 26, 48, 17,
25, 38, 1, 29, 28, 1, 42, 21, 7,
8, 6, 6, 47, 50, 6, 46
],
lineStyle: {
type: 'solid',
width: 5
}
}
]
};
thanks in advance
[UPDATE 1]
I added a function that translate the week number to the respective month:
getDateOfWeek(week: number, year: number): string {
let date = (1 + (week - 1) * 7);
let dateOfYear = new Date(year, 0, date)
let month = dateOfYear.toLocaleString('pt-BR', { month: 'short' });
month = month.charAt(0).toUpperCase() + month.slice(1).replace('.', '')
return month;
}
also added a axisLabel:
options: {
...,
axisLabel: {
formatter: (param: number) => {
return this.getDateOfWeek(param, 2021)
},
},
...,
}
Now i have the month name on xaxis as expected... Only need to suppress duplicated names or maybe define a limit for 12 ticks.
I've tried to use xaxis.splitNumber property, but as the docs says, it is not allowed for category axis...
I was wondering, if i could change the week number to a date object, like:
firstWeek = '2021-01-01'
secondWeek = '2021-01-08'
should i change it to time series and work with real dates on X Axis?
not sure if it would solve the problem or bring another :|
here is the result so far:
Solved adding a new xaxis layer and hide the first one...
xAxis: [
{
type: "category",
boundaryGap: false,
data: this.generateData(false, 51),
axisLabel: {
formatter: (param) => {
return this.getMonthFromWeek(param, 2021);
}
},
show: false
},
{
position: "bottom",
type: "category",
data: [
"Jan",
"Fev",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Out",
"Nov",
"Dez"
],
xAxisIndex: 2
}
],
here is sandbox code result!
I have a graph that won't cover the full chart area Horizontally
Here is the sample data that is used to achieve the graph
[
[
"2021-07-08",
53,
0,
53,
0,
38,
0
],
[
"2021-07-09",
11,
26,
27,
98,
20,
47
],
[
"2021-07-10",
80,
42,
14,
35,
20,
13
],
[
"2021-07-11",
16,
12,
17,
25,
47,
79
],
[
"2021-07-12",
41,
12,
10,
12,
64,
40
],
[
"2021-07-13",
32,
84,
30,
72,
19,
18
],
[
"2021-07-14",
12,
50,
44,
85,
25,
11
],
[
"2021-07-15",
43,
60,
26,
74,
88,
30
]
]
My options are
var options = {
legend: { position: 'bottom' },
chartArea:{left:20, right:0, top:0,width:'100%',height:'75%'}
};
See attached image with result
How do I make the Horizontal axis cover the whole chart?
I have a data frame in pyspark which has hundreds of millions of rows (here is a dummy sample of it):
import datetime
import pyspark.sql.functions as F
from pyspark.sql import Window,Row
from pyspark.sql.functions import col
from pyspark.sql.functions import month, mean,sum,year,avg
from pyspark.sql.functions import concat_ws,to_date,unix_timestamp,datediff,lit
from pyspark.sql.functions import when,min,max,desc,row_number,col
dg = sqlContext.createDataFrame(sc.parallelize([
Row(cycle_dt=datetime.datetime(1984, 5, 2, 0, 0), network_id=4,norm_strength=0.5, spend_active_ind=1,net_spending_amt=0,cust_xref_id=10),
Row(cycle_dt=datetime.datetime(1984, 6, 2, 0, 0), network_id=4,norm_strength=0.5, spend_active_ind=1,net_spending_amt=2,cust_xref_id=11),
Row(cycle_dt=datetime.datetime(1984, 7, 2, 0, 0), network_id=4,norm_strength=0.5, spend_active_ind=1,net_spending_amt=2,cust_xref_id=12),
Row(cycle_dt=datetime.datetime(1984, 4, 2, 0, 0), network_id=4,norm_strength=0.5, spend_active_ind=1,net_spending_amt=2,cust_xref_id=13),
Row(cycle_dt=datetime.datetime(1983,11, 5, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=0,net_spending_amt=8,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1983,12, 2, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=0,net_spending_amt=2,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984, 1, 3, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=1,net_spending_amt=15,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984, 3, 2, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=0,net_spending_amt=7,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984, 4, 3, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=0,net_spending_amt=1,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984, 5, 2, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=0,net_spending_amt=1,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984,10, 6, 0, 0), network_id=1,norm_strength=0.5, spend_active_ind=1,net_spending_amt=10,cust_xref_id=1 ),
Row(cycle_dt=datetime.datetime(1984, 1, 7, 0, 0), network_id=1,norm_strength=0.4, spend_active_ind=0,net_spending_amt=8,cust_xref_id=2 ),
Row(cycle_dt=datetime.datetime(1984, 1, 2, 0, 0), network_id=1,norm_strength=0.4, spend_active_ind=0,net_spending_amt=3,cust_xref_id=2 ),
Row(cycle_dt=datetime.datetime(1984, 2, 7, 0, 0), network_id=1,norm_strength=0.4, spend_active_ind=1,net_spending_amt=5,cust_xref_id=2 ),
Row(cycle_dt=datetime.datetime(1985, 2, 7, 0, 0), network_id=1,norm_strength=0.3, spend_active_ind=1,net_spending_amt=8,cust_xref_id=3 ),
Row(cycle_dt=datetime.datetime(1985, 3, 7, 0, 0), network_id=1,norm_strength=0.3, spend_active_ind=0,net_spending_amt=2,cust_xref_id=3 ),
Row(cycle_dt=datetime.datetime(1985, 4, 7, 0, 0), network_id=1,norm_strength=0.3, spend_active_ind=1,net_spending_amt=1,cust_xref_id=3 ),
Row(cycle_dt=datetime.datetime(1985, 4, 8, 0, 0), network_id=1,norm_strength=0.3, spend_active_ind=1,net_spending_amt=9,cust_xref_id=3 ),
Row(cycle_dt=datetime.datetime(1984, 4, 2, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=0,net_spending_amt=3,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 4, 3, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=0,net_spending_amt=2,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 1, 2, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=0,net_spending_amt=5,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 1, 3, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=1,net_spending_amt=6,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 3, 2, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=0,net_spending_amt=2,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 1, 5, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=0,net_spending_amt=9,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 1, 6, 0, 0), network_id=2,norm_strength=0.5, spend_active_ind=1,net_spending_amt=1,cust_xref_id=4 ),
Row(cycle_dt=datetime.datetime(1984, 1, 7, 0, 0), network_id=2,norm_strength=0.4, spend_active_ind=0,net_spending_amt=7,cust_xref_id=5 ),
Row(cycle_dt=datetime.datetime(1984, 1, 2, 0, 0), network_id=2,norm_strength=0.4, spend_active_ind=0,net_spending_amt=8,cust_xref_id=5 ),
Row(cycle_dt=datetime.datetime(1984, 2, 7, 0, 0), network_id=2,norm_strength=0.4, spend_active_ind=1,net_spending_amt=3,cust_xref_id=5 ),
Row(cycle_dt=datetime.datetime(1985, 2, 7, 0, 0), network_id=2,norm_strength=0.6, spend_active_ind=1,net_spending_amt=6,cust_xref_id=6 ),
Row(cycle_dt=datetime.datetime(1985, 3, 7, 0, 0), network_id=2,norm_strength=0.6, spend_active_ind=0,net_spending_amt=9,cust_xref_id=6 ),
Row(cycle_dt=datetime.datetime(1985, 4, 7, 0, 0), network_id=2,norm_strength=0.6, spend_active_ind=1,net_spending_amt=4,cust_xref_id=6 ),
Row(cycle_dt=datetime.datetime(1985, 4, 8, 0, 0), network_id=2,norm_strength=0.6, spend_active_ind=1,net_spending_amt=6,cust_xref_id=6 ),
Row(cycle_dt=datetime.datetime(1984, 4, 2, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 4, 3, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 1, 2, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 1, 3, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 3, 2, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 1, 5, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 1, 6, 0, 0), network_id=3,norm_strength=0.5, spend_active_ind=0,net_spending_amt=0,cust_xref_id=7 ),
Row(cycle_dt=datetime.datetime(1984, 1, 7, 0, 0), network_id=3,norm_strength=0.4, spend_active_ind=0,net_spending_amt=3,cust_xref_id=8 ),
Row(cycle_dt=datetime.datetime(1984, 1, 2, 0, 0), network_id=3,norm_strength=0.4, spend_active_ind=0,net_spending_amt=2,cust_xref_id=8 ),
Row(cycle_dt=datetime.datetime(1984, 2, 7, 0, 0), network_id=3,norm_strength=0.4, spend_active_ind=1,net_spending_amt=8,cust_xref_id=8 ),
Row(cycle_dt=datetime.datetime(1985, 2, 7, 0, 0), network_id=3,norm_strength=0.6, spend_active_ind=1,net_spending_amt=4,cust_xref_id=9 ),
Row(cycle_dt=datetime.datetime(1985, 3, 7, 0, 0), network_id=3,norm_strength=0.6, spend_active_ind=0,net_spending_amt=1,cust_xref_id=9 ),
Row(cycle_dt=datetime.datetime(1985, 4, 7, 0, 0), network_id=3,norm_strength=0.6, spend_active_ind=1,net_spending_amt=9,cust_xref_id=9 ),
Row(cycle_dt=datetime.datetime(1985, 4, 8, 0, 0), network_id=3,norm_strength=0.6, spend_active_ind=0,net_spending_amt=3,cust_xref_id=9 )
]))
I am trying to sumspend_active_ind for each cust_xref_id and keep those with sum more than zero. One way to do this is using grouby and join:
dg1 = dg.groupby("cust_xref_id").agg(sum("spend_active_ind").alias("sum_spend_active_ind"))
dg1 = dg1.filter(dg1.sum_spend_active_ind != 0).select("cust_xref_id")
dg = dg.alias("t1").join(dg1.alias("t2"),col("t1.cust_xref_id")==col("t2.cust_xref_id")).select(col("t1.*"))
The other way I can think of it is using window:
w = Window.partitionBy ('cust_xref_id')
dg = dg.withColumn('sum_spend_active_ind',sum(dg.spend_active_ind).over(w))
dg = dg.filter(dg.sum_spend_active_ind!=0)
which one of these methods (or any other method) is more efficient for what I am trying to do.
Thanks
You could try to open your spark-ui at localhost:4040, or see the query plan using the explain method:
(
dg
.groupby('cust_xref_id')
.agg(F.sum('spend_active_ind').alias('sum_spend_active_ind'))
.filter(F.col('sum_spend_active_ind') > 0)
).explain()
My drilldown works fine, yet I can't figure out how to make my drilldown chart title show the drilled point x value (datetime) in the format "Sales of YYYY-MM-DD".
Going back to initial chart title "Sales" (on drillup event) works good.
$(function () {
Highcharts.setOptions({
global: {
useUTC: false,
timeZoneOffset: -180
},
lang: {
drillUpText: ' < Back '
}
});
// Create the chart
$('#container').highcharts({
credits: {
enabled: false
},
xAxis: [{
id: 0,
minorTickLength: 0,
labels: {
y: 15,
format: '{value:%e %b}',
zIndex: 0
},
tickPixelInterval: 10,
tickWidth: 0,
title: {
text: null
},
tickColor: '#e0e0e0',
pointPadding: 0.05,
tickmarkPlacement: 'on',
type: 'datetime'
},{
id: 1,
minorTickLength: 0,
labels: {
y: 15,
zIndex: 0
},
tickPixelInterval: 2,
tickWidth: 0,
title: {
text: null
},
tickColor: '#e0e0e0',
pointPadding: 0.2,
tickmarkPlacement: 'on',
type: 'category',
lineWidth: 0
}],
yAxis: {
gridLineWidth: 0,
gridLineColor: '#e0e0e0',
labels: {
y: 0,
x: 0,
overflow: 'justify',
enabled: false,
maxStaggerLines: 0,
align: 'center'
},
title: {
margin: 0,
text: null
},
gridLineInterpolation: null
},
tooltip: {
enabled: false,
shared: true,
xDateFormat: '%e %b',
valueSuffix: ' Lt',
borderColor: 'null',
borderRadius: 10
},
plotOptions: {
areaspline: {
lineColor: '#c0c0c0',
marker: {
enabled: false,
fillColor: '#e0e0e0',
radius: 3,
lineWidth: 1,
lineColor: '#c0c0c0'
},
lineWidth: 1,
states: {
hover: {
marker: {
radius: 3,
lineWidth: 1
}
}
}
},
column: {
allowPointSelect: false,
cursor: 'pointer',
dataLabels: {
enabled: true,
inside: false,
overflow: 'none',
y: -10,
x: 0,
verticalAlign: 'middle',
padding: 0,
}
}
},
chart: {
events: {
drilldown: function(){
UpdateTitle('Sales of '+this)
},
drillup: function(){
UpdateTitle('Sales')
}
},
spacingBottom: 20,
type: 'column',
borderRadius: 2,
spacingTop: 0,
width: 1012,
marginLeft: 0,
pacingRight: 0,
marginBottom: 40,
marginRight: 0,
marginTop: 20,
height: 180,
spacingLeft: 0
},
title: {
margin: 10,
y: 15,
text: 'Sales',
x: 20,
align: 'left',
},
Exporting: {
scale: 1,
buttons: {
contextButton: {
enabled: false
}
},
enabled: false
},
legend: {
enabled: false,
symbolWidth: 12
},
series: [ {
index: 1,
type: 'column',
color: '#30bf09',
name: 'Sales',
data: [{
x: 1399410000000,
y: 16675,
drilldown: 'day01'
},{
x: 1399496400000,
y: 6906,
drilldown: 'day02'
},{
x: 1399582800000,
y: 5290,
drilldown: 'day03'
},{
x: 1399669200000,
y: 764,
drilldown: 'day04'
},{
x: 1399755600000,
y: 248,
drilldown: 'day05'
},{
x: 1399842000000,
y: 8585,
drilldown: 'day06'
},{
x: 1399928400000,
y: 5176,
drilldown: 'day07'
},{
x: 1400014800000,
y: 10836,
drilldown: 'day08'
},{
x: 1400101200000,
y: 13217,
drilldown: 'day09'
},{
x: 1400187600000,
y: 7213,
drilldown: 'day10'
},{
x: 1400274000000,
y: 711,
drilldown: 'day11'
},{
x: 1400360400000,
y: 1038,
drilldown: 'day12'
},{
x: 1400446800000,
y: 6612,
drilldown: 'day13'
},{
x: 1400533200000,
y: 14496,
drilldown: 'day14'
}]
},{
index: 0,
type: 'areaspline',
color: '#e0e0e0',
name: 'Planas',
data: [
[1399410000000, 2930],
[1399496400000, 2930],
[1399582800000, 2930],
[1399669200000, 0],
[1399755600000, 0],
[1399842000000, 2930],
[1399928400000, 2930],
[1400014800000, 2930],
[1400101200000, 2930],
[1400187600000, 2930],
[1400274000000, 0],
[1400360400000, 0],
[1400446800000, 2930],
[1400533200000, 2930]
]
}],
drilldown: {
activeAxisLabelStyle: {
textDecoration: 'none',
fontWeight: 'regular',
color: '7f7f7f'
},
activeDataLabelStyle: {
textDecoration: 'none',
fontWeight: 'semi-bold',
color: '4c4c4c'
},
drillUpButton: {
relativeTo: 'spacingBox',
position: {
align: 'right',
x: 0,
y: 0,
verticalAlign: 'top'
}
},
series: [{
id: 'day01',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Presta', 2000],
['Export', 600],
['ESET', 75],
['SoftMak', 75],
['Google', 750],
['Blancco', 0],
['Axence', 200],
['Kiti', 1500],
['...', 0],
['...', 0],
['Box', 550],
['Nuoma', 75]
]
},{
id: 'day02',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftM', 75],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ]
]
},{
id: 'day03',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day04',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day05',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day06',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day07',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day08',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day09',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day10',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day11',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day12',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day13',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75]
]
},{
id: 'day14',
xAxis: 1,
data: [
['ESET', 10000],
['OERP', 4000],
['Google', 2000],
['Export', 600],
['SoftMaker', 75],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ],
[ , ]
]}
]
}
})
var chart = $('#container').highcharts();
function UpdateTitle(argument1) {
chart.setTitle({text: argument1})
}
In a drilldown event you have access to clicked point: e.point. For example to get timestamp of clicked point use e.point.x. Now simply parse that timestamps to required format and it should work. See: http://jsfiddle.net/nJFZN/
drilldown: function (e) {
UpdateTitle('Sales of ' + e.point.x)
},