Linking graphs of two Shield UI Charts - javascript

I have a question, regarding the shield ui chart library. Essentially, I have two charts on the same page. I would like to co-relate them in the sense that when the user selects a bar from one of the charts, the other control would be populated with data, related to the selection.

Below is an example showing two graphs. On the left are 4 quartery data sets, using the rangebar layout. Clicking on each one of them shows detailed information about the data on the right graph.
<script type=""text/javascript"">
$(function () {
$(""#container1"").shieldChart({
theme: ThemeChooser.theme,
events: {
pointSelect: function pointSelectHandler(args) {
var localData;
var headerText = ""Data For : "" + args.point.name;
if (args.point.x == 0) {
localData = [12, 3, 4, 2, 12, 3, 4, 17, 22, 34, 54, 67];
}
else if (args.point.x == 1) {
localData = [3, 9, 12, 14, 22, 32, 45, 12, 67, 45, 55, 7];
}
else if (args.point.x == 2) {
localData = [23, 19, 11, 134, 242, 352, 435, 22, 637, 445, 555, 57];
}
else {
localData = [13, 19, 112, 114, 212, 332, 435, 132, 67, 45, 55, 7];
}
var containter = $(""#container2"").swidget();
containter.destroy();
$(""#container2"").shieldChart(
{
exportOptions:
{
image: false,
print: false
},
primaryHeader: {
text: headerText
},
dataSeries: [
{
seriesType: 'line',
collectionAlias: 'Q Data',
data: localData
}
]
}
);
}
},
exportOptions:
{
image: false,
print: false
},
seriesSettings: {
rangebar:
{
enablePointSelection: true
}
},
tooltipSettings: {
customPointText: 'Low Value: <b>{point.low}</b></br>High Value:<b> {point.high}</b>'
},
axisY: {
title: {
text: ""Quarterly""
}
},
axisX: {
categoricalValues: [""Q1"", ""Q2"", ""Q3"", ""Q4""]
},
primaryHeader: {
text: ""Quarterly performance""
},
dataSeries: [
{
seriesType: 'rangebar',
collectionAlias: 'Low/High ',
data: [[3, 9], [12, 23], [1, 17], [-3, 12]]
}
]
});
$(""#container2"").shieldChart({
theme: ThemeChooser.theme,
exportOptions:
{
image: false,
print: false
},
primaryHeader: {
text: ""Values for specific quarter""
},
dataSeries: [
{
seriesType: 'line',
collectionAlias: 'Q Data',
data: [12, 3, 4, 2, 12, 3, 4, 17, 22, 34, 54, 67]
}
]
});
});
</script>"

Related

ASP.NET Populate Apex Chart using a String Array from Controller

I am trying to populate the chart data from within my controller. I think im on the right path by using a string array but ive also tried an int array and had the same result.
Currently the page shows this,
Picture of the chart live
And this is my output on the Dev Tools,
Picture of Dev Tools Console
Here is how I'm currently grabbing the data from my Model,
<script type="text/javascript">
$(document).ready(function () {
var error = #((TempData["errorMessage"] != null).ToString().ToLower());
if (error == true) {
console.log("hello world");
$('#errorModal').modal('show');
}
var EmbroideryTally = #Html.Raw(Json.Serialize(Model.EmbroideryTally));
console.log(EmbroideryTally);
var options = {
chart: {
height: 550,
type: "line",
stacked: false
},
colors: ["#E5AE10", "#6D77E0", "#15BE90", "#E15C79", "#68727A"],
series: [
{
name: "Embroidery",
data: []
}
//,
//{
// name: "Engraving",
// data: [108, 128, 98, 83, 193, 26, 55, 66, 79, 29, 37, 66, 154, 64, 104, 172, 34, 29, 37, 66, 44, 150, 50, 200]
//},
//{
// name: "Metal",
// data: [167, 108, 27, 177, 198, 12, 141, 172, 118, 175, 165, 52, 19, 157, 33, 42, 121, 176, 43, 14, 158, 80, 82, 125]
//},
//{
// name: "Uvp",
// data: [0, 54, 2, 13, 199, 46, 165, 183, 167, 7, 152, 185, 17, 27, 169, 25, 9]
//},
//{
// name: "Unknown",
// data: [93, 170, 52, 16, 126, 176, 82, 40, 132, 4, 62, 43, 35, 34, 195, 75, 122]
//}
],
stroke: {
width: [8, 8, 8, 8, 8]
},
plotOptions: {
bar: {
columnWidth: "20%"
}
},
xaxis: {
categories: [01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
},
labels: ['Embroidery', 'Engraving', 'Metal', 'UV', 'Unknown'],
noData: { text: 'Waiting for scans...', style: { color: '#ffffff' }}
};
var barCodeChart = new ApexCharts(document.querySelector("#barCodeChart"), options);
barCodeChart.render();
barCodeChart.updateSeries([{
name: "Embroidery",
data: [#Html.Raw(Json.Serialize(Model.EmbroideryTally))]
}]);
});
</script>
Here is my Model
namespace MyApp.Models
{
public class BarcodeViewModel
{
public BarcodeViewModel()
{
BarcodeScan = new BarcodeScan();
EmbroideryTally = new String[24];
}
public string[] EmbroideryTally { get; set; }
}
}
And heres my Controller (I've taken a good chunk of stuff out as its not important)
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Create([Bind("BarcodeScanCode")] BarcodeScan barcode)
{
try
{
_barcodeViewModel.EmbroideryTally[0] = "21";
_barcodeViewModel.EmbroideryTally[1] = "14";
_barcodeViewModel.EmbroideryTally[2] = "64";
_barcodeViewModel.EmbroideryTally[3] = "150";
_barcodeViewModel.EmbroideryTally[4] = "32";
catch (Exception e)
{
Console.WriteLine("An issue has arisen:" + e.Message);
TempData["errorMessage"] = "An ERROR has occurred. Barcode not properly submitted. Barcode: " + barcode.BarcodeScanCode;
}
finally
{
await conn.CloseAsync();
}
return View("Index", _barcodeViewModel);
}

Group data by weekdays in Highchart

I'm plotting a graph that needs to combine data of a selected date range to weekdays i mean if i selected a date range from ex: 2021-05-01 to 2021-05-31 in that consider 2021-05-01,2021-05-08,2021-05-15 these days are Friday so i need to combine datas of these dates and show as one data with label friday. With the current options that i used the chart is plotting like this. Is there any ways to display it correctly.
Demo Fiddle
This is the way that i currently getting the result
This is the result that i'm expecting
These are the current configd that i'm using in the highchart.
Highcharts.chart("multistackedbarchart-II", {
chart: {
type: "column",
},
title: {
text: "Sent/Received Comparison",
},
xAxis: {
title: {
text: "Day",
},
categories: [labels],
},
yAxis: {
min: 0,
title: {
text: "",
},
stackLabels: {
enabled: false,
style: {
fontWeight: "bold",
color:
// theme
(Highcharts.defaultOptions.title.style && Highcharts.defaultOptions.title.style.color) ||
"gray",
},
},
},
legend: {
align: "center",
verticalAlign: "bottom",
x: 0,
y: 0,
},
tooltip: {
headerFormat: "<b>{point.x}</b><br/>",
pointFormat: "{series.name}: {point.y}",
},
plotOptions: {
column: {
stacking: "normal",
dataGrouping: {
forced: true,
units: [['day', [1]]]
}
},
},
series: chartdata.multistackedbarchart,
credits: {
enabled: false,
},
});
Highcharts.setOptions({ lang: { noData: "No Data Available" } });
You can make a special function to do this sorting by using Array.map() and Array.filter() methods:
const categories = [
"2021-08-04",
"2021-08-05",
"2021-08-06",
"2021-08-07",
"2021-08-08",
"2021-08-09",
"2021-08-10",
"2021-08-11",
"2021-08-12",
"2021-08-13",
"2021-08-14",
"2021-08-15",
"2021-08-16",
"2021-08-17",
"2021-08-18",
"2021-08-19",
"2021-08-20",
"2021-08-21",
"2021-08-22",
"2021-08-23",
"2021-08-24",
"2021-08-25",
"2021-08-26",
"2021-08-27",
"2021-08-28",
"2021-08-29",
"2021-08-30",
"2021-08-31",
"2021-09-01",
"2021-09-02",
"2021-09-03",
"2021-09-04",
"2021-09-05",
"2021-09-06",
"2021-09-07",
"2021-09-08",
"2021-09-09",
"2021-09-10",
"2021-09-11",
"2021-09-12",
"2021-09-13",
"2021-09-14",
"2021-09-15",
"2021-09-16",
"2021-09-17",
"2021-09-18",
"2021-09-19",
"2021-09-20",
"2021-09-21",
"2021-09-22",
"2021-09-23",
"2021-09-24",
"2021-09-25",
"2021-09-26",
"2021-09-27",
"2021-09-28",
"2021-09-29",
"2021-09-30",
"2021-10-01",
"2021-10-02",
"2021-10-03",
"2021-10-04",
"2021-10-05",
"2021-10-06",
"2021-10-07",
"2021-10-08",
"2021-10-09",
"2021-10-10",
"2021-10-11",
"2021-10-12"]
const messagesSent = [ 32,
60,
71,
3,
1,
25,
16,
23,
28,
25,
2,
1,
43,
49,
32,
35,
26,
2,
1,
8,
36,
47,
15,
20,
2,
1,
2,
18,
20,
30,
43,
4,
4,
15,
14,
48,
39,
3,
2,
0,
48,
34,
15,
9,
1,
3,
1,
85,
27,
72,
11,
4,
2,
0,
29,
13,
21,
15,
32,
2,
0,
58,
37,
37,
24,
5,
1,
0,
0,
0]
const messagesReceived = [29,
79,
80,
7,
2,
24,
32,
23,
44,
42,
3,
1,
65,
69,
46,
47,
23,
3,
1,
28,
35,
65,
22,
19,
4,
1,
7,
10,
32,
31,
13,
8,
2,
4,
48,
53,
46,
7,
4,
0,
48,
40,
23,
18,
2,
6,
2,
79,
25,
86,
9,
8,
5,
0,
25,
18,
18,
14,
37,
2,
0,
52,
70,
27,
25,
17,
1,
0,
0,
0]
const organizeData = (days, sent, received) => {
const dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
// get name of weekday
const getDayOfWeek = date => {
const dayOfWeek = new Date(date).getDay();
return isNaN(dayOfWeek) ? null : dayNames[dayOfWeek];
}
return dayNames.map((dayName) => {
let correspondingMessagesSent = []
let correspondingMessagesReceived = []
const matchedDays = days.filter((day, index) => {
if(dayName === getDayOfWeek(day)) {
correspondingMessagesSent.push(sent[index])
correspondingMessagesReceived.push(received[index])
return day
}
})
return { [dayName]: { dates: matchedDays,
sent: correspondingMessagesSent,
received: correspondingMessagesReceived} }
})
}
console.log(organizeData(categories, messagesSent, messagesReceived))
/* This is not a part of answer. It is just to give the output fill height. So IGNORE IT */
.as-console-wrapper { max-height: 100% !important; top: 0; }

Limit x-axis in Apexcharts.js

I want to limit the x-axis in the bar graph I'm using, I have multiple values but I want to show only 7 and then the user can scroll to see the remaining. Does this option exist?
Setting the value of the xaxis.range property should help.
var options = {
series: [
{
name: 'PRODUCT A',
data: [44, 55, 41, 67, 22, 43, 13, 23, 20, 8, 13, 27]
}, {
name: 'PRODUCT B',
data: [13, 23, 20, 8, 13, 27, 11, 17, 15, 15, 21, 14]
}, {
name: 'PRODUCT C',
data: [11, 17, 15, 15, 21, 14, 44, 55, 41, 67, 22, 43]
}
],
chart: {
type: 'bar',
height: 350,
stacked: true,
toolbar: {
show: true
}
},
xaxis: {
range: 7
}
};
var chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();

I was trouble bubble value in highcharts .How to show by default value in series

I was trouble bubble value in highcharts .How to show by default value in series
I want show by default value in bubble. when i was hovered in bubble showing series value but i want to show by default series value is this possible.?
https://jsfiddle.net/Kondaldurgam/q734jr5t/
Highcharts.chart('container', {
chart: {
type: 'bubble',
plotBorderWidth: 0,
zoomType: 'xy'
},
title: {
text: 'Highcharts bubbles with radial gradient fill'
},
xAxis: {
gridLineWidth: 1
},
yAxis: {
startOnTick: false,
endOnTick: false
},
series: [{
data: [
[9, 81, 63],
[98, 5, 89],
[51, 50, 73],
[41, 22, 14],
[58, 24, 20],
[78, 37, 34],
[55, 56, 53],
[18, 45, 70],
[42, 44, 28],
[3, 52, 59],
[31, 18, 97],
[79, 91, 63],
[93, 23, 23],
[44, 83, 22]
],
marker: {
fillColor: {
radialGradient: { cx: 0.4, cy: 0.3, r: 0.7 },
stops: [
[0, 'rgba(255,255,255,0.5)'],
[1, Highcharts.Color(Highcharts.getOptions().colors[0]).setOpacity(0.5).get('rgba')]
]
}
}
}, ]
});
Add plot options in chart with datalables
Fiddle link
plotOptions: {
bubble: {
dataLabels: {
enabled: true,
x:40,/*shifting values to right side*/
format: '({point.x},{point.y})<br>Size:{point.z}'
},
}
},

Highcharts stacked column: show total when a stack is hidden

I have a stacked column chart with three stacks per column. See https://jsfiddle.net/Lfvnraqd/1/
The tooltip shows the numbers for the individual stack as well as the total of all three stacks (i.e. the total of all proceedings per year). This works fine as long as all stacks are shown. But when I hide one or two stacks by clicking on the corresponding item in the legend, the total shown in the tooltip is that of all visible stacks, but I want it to still show the total of all three stacks. If possible without the need to have a separate series for the total numbers.
Is there a way to do that?
Code:
$(function () {
Highcharts.setOptions({
colors: ['#f59000', '#2274c1', '#90aaef']
});
$('#container').highcharts({
chart: {
borderColor: '#cccccc',
borderWidth: 2,
marginTop: 43,
type: 'column'
},
xAxis: {
categories: ['2004', '2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015'],
tickLength: 20
},
yAxis: {
min: 0,
max: 45,
reversedStacks: false,
tickInterval: 5,
title: {
text: null
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
}
}
},
credits: {
enabled: false
},
title: {
text: 'Number of procedures per year',
y: 18
},
tooltip: {
headerFormat: '<b>Year {point.x}</b><br/>',
pointFormat: '{series.name}: {point.y}<br/>Total procedures: {point.stackTotal}'
},
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: [{
name: 'Resolved before conciliation',
data: [14, 12, 10, 13, 10, 7, 11, 11, 11, 8, 8, 10]
}, {
name: 'Conciliation successful',
data: [2, 4, 5, 1, 2, 7, 6, 4, 1, 1, 3, 0]
}, {
name: 'Expert\'s decision',
data: [7, 13, 20, 10, 20, 19, 20, 26, 25, 19, 18, 17]
}]
});
});
Summing of the points values need to be done manually because the chart operate only on visible data.
Before you set data in the chart, you calculate its sum:
var data1 = [14, 12, 10, 13, 10, 7, 11, 11, 11, 8, 8, 10];
var data2 = [2, 4, 5, 1, 2, 7, 6, 4, 1, 1, 3, 0];
var data3 = [7, 13, 20, 10, 20, 19, 20, 26, 25, 19, 18, 17]
var sums = Object.keys(data1).map(i => {
return data1[i] + data2[i] + data3[i];
});
and access the propert sum in tooltip.pointFormatter
pointFormatter: function () {
return this.series.name + ': ' + this.y + '<br/>Total procedures: ' + sums[this.x];
}
Example: https://jsfiddle.net/Lfvnraqd/2/

Categories

Resources