Vue Highcharts display graph for each user after routing - highcharts

I'm using Vue cli and Highcharts. I have a user profile which displays some info about a user like so:
<div class="top" v-for="(item, index) in arrays" :key="item.id" v-bind:id="item.name">
<div> <p class="p"> {{ item.name }}</p> </div>
<div class="box" #click="route()">Rate</div>
which is displaying data from an array in vuex:
export default new Vuex.Store({
state: {
arrays: [
{
name: 'Bethany',
rate: [60, 75, 70, 85, 65],
Temp: [35, 37, 38, 26],
},
{
name: 'Sam',
rate: [70, 95, 60, 65, 83],
Temp: [36, 35.8, 37, 36]
},
]
I'm using Highcharts to display the rate and Temp and am routing to the charts with the route function.
route: function () {
this.$router.replace({ name: "Charts" });
},
My chart looks like this:
this.target = Highcharts.stockChart(this.$el, {
Chart: {
renderTo: 'container'
},
xAxis: [{
format: '{value}',
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
}],
yAxis: [{
labels: {
format: '{value}',
},
}],
legend: {
layout: 'vertical',
align: 'left',
x: 120,
verticalAlign: 'top',
y: 100,
floating: true,
},
series: [ {
name: 'Rate',
type: 'spline',
data: this.rate,
}],
});
},
Right now I have it just displaying data like so:
data : function() {
return {
target: undefined,
rate: this.$store.state.arrays[0]['rate'],
}
},
But I need a way to do it for all rates in array.
I'm looking for a way to display the series data for each users rate. So when I click on Bethany rate box I'm routed to the charts page with series data displaying the rates for Bethany.
Thanks!

You could add the current person name as a query parameter to your route:
route: function () {
const name = "Bethany"; // TODO: use actual person name...
this.$router.replace({ name: "Charts", query: { person: name } });
},
Then change:
this.$store.state.arrays[0]['rate'];
to something like:
this.$store.state.arrays.find(x => x.name === this.$route.query.person).rate;

Related

Highcharts series label legend in one line

I need to show highcharts api series name in one line but not able to get it correctly.
When viewport width is larger then it's not an issue but on narrow width the third legend item drops to new line. Due to SVG rendering, I am not able to apply CSS into group element.
In any case active users just wraps to second line and I am not able to set width of parent group element. So far I have tried all legend default options but it didn't work.
So any help would be great.
https://jsfiddle.net/h28jv3zL/
Highcharts.chart('container', {
chart: {
type: 'column'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
legend: {
align: "left",
x: 0,
y: 0,
itemWidth: 100,
// symbolWidth: 0,
// symbolHeight: 0,
// symbolRadius: 0,
verticalAlign: "top",
layout: "horizontal",
floating: false,
backgroundColor: "white",
shadow: false,
itemStyle: {
"fontWeight": "normal",
"color": "#101010",
"textOverflow": "normal",
"width": "auto",
"white-space": "nowrap",
'padding-right': "10px"
}
},
plotOptions: {
series: {
fillOpacity: 0.1
}
},
series: [{
name: "Inactive Users",
data: [10,11,12],
color: "#D8D8D8",
//showInLegend: false
},
{
name: "New Users",
data: [10,11,12],
color: "#696969",
//showInLegend: false
},
{
name: "Active Users",
data: [10,11,12],
color: "#202020",
//showInLegend: false
},]
});
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 400px"></div>
You can add some logic to check the chart.plotWidth and base on that substract series name or hide it inside the labelFormatter callback.
Demo: https://jsfiddle.net/BlackLabel/souphrg9/

plotting multiple columns on same chart in highcharts

I am trying to plot multiple column graphs on the same chart, stacked on each other. This is an example of desired output.
Each colored column segment represents percent of team to have reached a given level by the end of the given month. So it's like 4 separate column charts stacked. I think this is different than grouped and stacked, but may be mistaken.
Thanks for any feedback.
This can be done with a combination of stacked and column range. There are a few caveats with this in that you have to have a category for your yAxis which causes some funkiness with how you set your series' data values. I opted for one method and I am sure there are others. What I did was first set the chart type to 'columnrange':
chart: {
type: 'columnrange'
},
Then I set up the yAxis properties to use categories:
yAxis: {
categories: ['Level 0', 'Level 1', 'Level 2', 'Level 3'],
Since the offset of the category is in-between the tick marks of the axis I removed them and set the start position to not be on the tick:
startOnTick: false,
min: .5,
gridLineWidth: 0,
Up next I have to set the format of the labels (essentially just hiding the first label):
labels: {
formatter: function() {
var label = this.axis.defaultLabelFormatter.call(this);
if (!this.isFirst) {
return label;
}
}
},
Now I create plotLines to mimic the gridlines with the last one a different color to denote the "Target":
plotLines: [{
color: '#e6e6e6',
width: 1,
value: 1
}, {
color: '#e6e6e6',
width: 1,
value: 2
}, {
color: 'red',
width: 2,
value: 3,
label: {
text: 'Target'
}
}]
Now I setup the plotOptions for this chart. Note that the stacking parameter is not listed in the API as being part of the columnrange type but it still functions (as of this answer using v5.0):
plotOptions: {
columnrange: {
stacking: true
}
},
Okay, almost there. I then set up the series data:
series: [{
name: 's1',
data: [
[0, .64],
[0, .9],
[0, 1]
]
}, {
name: 's2',
data: [
[null, null],
[1, 1.1],
[1.0, 1.5]
]
}, {
name: 's3',
data: [
[null, null],
[null, null],
[2.0, 2.5]
]
}]
The important part of the data values is that each "level" is a whole integer such that Level 1 is from 0 to 1 and Level 2 is from 1 to 2 and Level 3 is from 2 to 3. This works out good as you try to determine your percentage in each level for each month as they are still in uniform increments.
I did not modify the tooltip as you gave no specs on that.
Sample jsFiddle and full code:
$(function() {
Highcharts.chart('container', {
chart: {
type: 'columnrange'
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
categories: ['Level 0', 'Level 1', 'Level 2', 'Level 3'],
startOnTick: false,
min: .5,
gridLineWidth: 0,
title: {
text: null
},
labels: {
formatter: function() {
var label = this.axis.defaultLabelFormatter.call(this);
if (!this.isFirst) {
return label;
}
}
},
plotLines: [{
color: '#e6e6e6',
width: 1,
value: 1
}, {
color: '#e6e6e6',
width: 1,
value: 2
}, {
color: 'red',
width: 2,
value: 3,
label: {
text: 'Target'
}
}]
},
plotOptions: {
columnrange: {
stacking: true
}
},
legend: {
enabled: true
},
series: [{
name: 's1',
data: [
[0, .64],
[0, .9],
[0, 1]
]
}, {
name: 's2',
data: [
[null, null],
[1, 1.1],
[1.0, 1.5]
]
}, {
name: 's3',
data: [
[null, null],
[null, null],
[2.0, 2.5]
]
}]
});
});

Remove Highchart line when no value

I have a line chart like this:
http://jsfiddle.net/vbLdsodu/
How do i remove or hide the line after july? I want the date axis to continue but don't show the line where the values is 0.
$(function () {
$('#container').highcharts({
title: {
text: 'Monthly Average Temperature',
x: -20 //center
},
subtitle: {
text: 'Source: WorldClimate.com',
x: -20
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: 'Temperature (°C)'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: '°C'
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'middle',
borderWidth: 0
},
series: [{
name: 'Tokyo',
data: [7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 0, 0, 0, 0, 0]
}]
});
});
You can replace 0 with null in the data which will then keep the axis listing the months, but stop the line from drawing.
It's also possible to do this part way through the graph and the line will draw from the next data point.

Add a Specific Y-Axis Label with Highcharts

I have a graph with a labelled Y-Axis with points 1 through 100. In addition to the regularly spaced labels (0, 10, 20, etc), I want to add a label for an arbitrary point, say 47. Is this possible with highcharts?
You can add a specific line to the yAxis with the plotLines option.
yAxis: {
plotLines: [{
value: 47,
color: 'rgb(216, 216, 216)',
width: 1,
}]
},
http://jsfiddle.net/nicholasduffy/wa6ukyyp/1/
EDIT:
This seems a bit of a hack, but you could fake the label.
yAxis: {
plotLines: [{
value: 47,
color: 'rgb(216, 216, 216)',
width: 1,
label : {
text: '47',
x: -30,
y: 2
}
}]
},
http://jsfiddle.net/nicholasduffy/wa6ukyyp/2/
Based on your comment, you can add a custom tick with tickPositioner function, with a code like this
$(function () {
$('#container').highcharts({
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
tickInterval: 20, //sets the interval ticks
tickPositioner: function(){
var ticks = this.tickPositions; // gets the tick positions
ticks.push(47); // adds the custom tick
ticks.sort(function(a, b) {
return a - b; // sorts numerically the ticks
});
return ticks; // returns the new ticks
}
},
series: [{
data: [29.9, 71.5, 86.4, 29.2, 44.0, 76.0, 93.5, 98.5, 16.4, 94.1, 95.6, 54.4]
}]
});
});
JSFiddle demo
I think the solution I found that comes closest is to create a line of zero thickness and label the line:
plotLines: [{
value: cutoff,
color: 'rgb(216, 216, 216)',
width: 0,
label: {
text: 'label_name',
style: {
color: 'grey',
fontweight: 'bold'
}
}
}],
The label_name goes pretty close to the Y-Axis, and it gets the point across without putting a tooltip onto the graph

Highcharts: Logarithmic chart with Y Axis [100, 99.9, 99, 90, 0]

I am trying to use Highcharts to generate our website's availability information.
The Y axis is availability in percentage, the expected labels are:
[100, 99.9, 99, 90, 0]
code:
http://jsfiddle.net/2E9vF/1/
$(function () {
$('#container').highcharts({
chart: {
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: {
title: {
text: "AVAILABILITY %"
},
labels: {
formatter: function() {
return 100-this.value;
}
},
type: 'logarithmic',
reversed:true,
min:0.01,
plotLines: [{
color: '#CCCCCC',
width: 2,
value: 0.1,
dashStyle: 'ShortDot'
},{
color: 'red',
width: 2,
value: 1,
dashStyle: 'ShortDot'
},{
color: '#CCCCCCC',
width: 2,
value: 10,
dashStyle: 'ShortDot'
}],
},
tooltip: {
formatter: function() {
return 'x:'+ this.x +'<br>'+
'y:'+ (100-this.y);
}
},
series: [{
// real data:
// [90, 98, 99.7, 100, 100, 99.9, 99.7, 90, 91, 98, 96, 97.3]
data: [10, 2, 0.3, 0, 0, 0.1, 0.3, 10, 9, 2, 4, 2.7]
}]
});
});
However, I have two issues that I need help with:
I cannot draw 100 in the y axis
Orginal data with value 100 cannot be shown in the chart
Here is the expected chart:
http://www.shareimage.ro/images/0j1o0bnccavkqds8icuy.jpg
In general negative numbers and zero-based are not supported, but you can workaround this: http://jsfiddle.net/2E9vF/2/
In steps:
Assume that value 0 will be represented as other one, for example 0.001 (or lower)
Set min for yAxis to that value
Update formatters for tooltip and yAxis.labels accordingly:
tooltip: {
formatter: function() {
if(this.y === 0.001) {
return 'x:'+ this.x +'<br>'+ 'y:100';
} else {
return 'x:'+ this.x +'<br>'+ 'y:'+ (100-this.y);
}
}
},
And:
yAxis: {
labels: {
formatter: function() {
if(this.isFirst) {
return 100;
}
return 100-this.value;
}
}
}

Resources