Incorrect display of Morris Area chart and missing x-axis data - morris.js

I would like to know if someone can point me to the right direction. I have a View query named 'VwDashBoard_Areachart' that contains the following five fields with some information from the MSSQL server:
+-----+------+-----+-----+-----+
| ID | Year | OC | SS | ST |
+-----+------+-----+-----+-----+
| 1 | 2017 | 1 | 1 | 3 |
| 2 | 2018 | 1 | 1 | 2 |
| 3 | 2019 | 1 | 1 | 2 |
+-----+------+-----+-----+-----+
and I would like to present the data in the Morris Area Chart. I have the following code in the controller below:
public ActionResult AreaChart()
{
var mc = from mon in db.VwDashBoard_Areachart
select new
{
year = mon.Year,
value = mon.SS,
value1 = mon.OC,
value2 = mon.ST,
};
return Json(mc, JsonRequestBehavior.AllowGet);
}
And here's my script:
$(document).ready(function () {
$.get('#Url.Action("AreaChart")', function (result) {
new Morris.Area({
// ID of the element in which to draw the chart.
element: 'morris-area-charts',//'myfirstchart',
data: result,
xkey: 'year',
ykeys: ['value', 'value1', 'value2'],
labels: ['OC', 'SS', 'ST'],
pointFillColors: ['#ffffff'],
lineColors: ['#ccc', '#7a6fbe', '#28bbe3'],
redraw: true,
lineWidth: [1, 1, 1],
pointSize: 1,
});
});
});
This is the code from the razor:
<div class="panel-body">
<div id="morris-area-charts"></div>
</div>
Now when I run the script, it displays the Area chart but the chart display looks incorrect and does not display the year on the x-axis. However, the same result looks good if I display the chart as a bar chart.
I was wondering if I have forget to include something in the script or controller or the presentation of data layout from the View query needs to be modified in order to display the Area chart correctly.
I have tried putting in some static data and the Area chart displays correctly. The issue is when I am trying to fetch data from database. Any help would be really appreciated.

Your code looks good. Set the parseTime parameter to false to avoid Morris interpreting dates:
parseTime: false
Please try the following snippet based on your data:
var result = [
{ "year": "2017", "value": 1, "value1": 1, "value2": 3 },
{ "year": "2018", "value": 1, "value1": 1, "value2": 2 },
{ "year": "2019", "value": 1, "value1": 1, "value2": 2 }
];
new Morris.Area({
element: 'morris-area-charts',
data: result,
xkey: 'year',
ykeys: ['value', 'value1', 'value2'],
labels: ['OC', 'SS', 'ST'],
pointFillColors: ['#ffffff'],
lineColors: ['#ccc', '#7a6fbe', '#28bbe3'],
redraw: true,
lineWidth: [1, 1, 1],
pointSize: 1,
parseTime: false
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/morris.js/0.5.1/morris.css" rel="stylesheet" />
<div class="panel-body">
<div id="morris-area-charts"></div>
</div>

Related

How can I use Beautiful Soup to get the value from a dictionary that is inside of a <script> tag

How can I use Beautiful Soup to get a value of productId from the following <script> tag
soup.find('script')
<script>
gtmData.productData['34597834'] = {
"productId": 1234,
"foo": 1,
"bar": 2,
}
<script>
I want to retrieve the value of productId
you can print the soup object as a text.
import re
data = """gtmData.productData['34597834'] = {
"productId": 1234,
"foo": 1,
"bar": 2,
}"""
print(re.search(r"productId\": (\d*)", data).group(1))
Output:
1234
Also there's several ways, such as load it in JSON to parse whatever you want.
Another way, with no regex:
scr = """[your script above]"""
items = scr.split('{')[1].split('}')[0].split(',')
for item in items:
if ':' in item:
product = item.split(': ')
print(product[0].strip(), product[1])
Output:
"productId" 1234
"foo" 1
"bar" 2

Filtering through 2 differents components after rendering them

I'm stuck with this problem : I'm trying to order 2 same-level components who both have their own datas with their own properties. But the 2 differents datas have the same "position" property.
DB structure
Chapter
chapterId
title (string)
position (integer)
Page
pageId
name (string)
position (integer)
body (text)
Here is my Summary.vue
<template>
<div>
<summary-chapter v-for="chapter in data.chapters" :chapter="chapter"></summary-chapter>
<summary-page v-for="page in data.pages" :page="page"></summary-page>
</div>
</template>
The data variable is :
data :
{
'chapters' : { {chapterId: 1, ...}, {chapterId: 2, ...}, {chapterId: 3, ...}, ... },
'pages' : { {pageId: 1, ...}, {pageId: 2, ...}, {pageId: 3, ...}, ... }
}
I'm looking for this kind of results : Mixed
Pos: 1 - Page with id of 12
Pos: 2 - Chapter with id of 7
Pos: 3 - Chapter with id of 2
Pos: 4 - Page with id of 4
Pos: 5 - Page with id of 13
Pos: 6 - Chapter with id of 1
But I always have all chapters first and then all pages :
Pos: 2 - Chapter with id of 7
Pos: 3 - Chapter with id of 2
Pos: 6 - Chapter with id of 1
Pos: 1 - Page with id of 12
Pos: 4 - Page with id of 4
Pos: 5 - Page with id of 13
I really have no clue how to do it the right way.
I tried to filter through a computed data property
I try dto built a parent component Summary row taht contains a chapter component or a page component depending on the type
I try 100 other ways ... :(
Do you guys have a tip ?
Thanks in advance for your time.
Louis
One way to solve this problem is combine those two arrays then sort by its position:
computed: {
sortedItems () {
let chapters = this.chapters.map(chapter => ({ ...chapter, type: 'chapter' }))
let pages = this.pages.map(page => ({ ...page, type: 'page' }))
return []
.concat(chapters)
.concat(pages)
.sort((a, b) => (a.position - b.position))
}
}
Then in you template render it by type:
<template v-for='item in sortedItems'>
<summary-chapter v-if='item.type === "chapter"' :chapter='item'/>
<summary-page v-if='item.type === "page"' :page='item'/>
</template>

How to work vue i18n pluralization?

I have locale messages the below:
timing: {
viewer: {
count: 'нету таймингов | 1 тайминг | 2 тайминга | 3 тайминга | 4 тайминга | {count} таймингов'
}
}
My template the below:
<span>{{ $tc('timing.viewer.count', 50, {count: 50}) }}</span>
Output the below:
<span>2 тайминга</span>
Why?? tag span must have "50 таймингов"
Your template is wrong.
Try it like this
timing: {
viewer: {
count: 'нету таймингов | 1 тайминг | {count} таймингов'
}
}
When using the count version of $tc i18n will look at the 3rd argument in the template.

Datatable component not aligned properly

I'm using a simple table in conjunction with datatable.js.
If I have 6 or 7 columns no problem. The search and paginator align correctly, but with 3 or 4 columns it shows in three columns.
In https://datatables.net/examples/basic_init/dom.html
show how to properly configure this, but I'm using thymeleaf and complains about the syntax
UPDATE 1
I have posted my question in:
https://datatables.net/forums/discussion/45926/dom-in-thymeleaf-html-pages
and this is that post:
Trying to add the code in: https://datatables.net/examples/basic_init/dom.html
in a thymeleaf html page, but it complains about this code:
"dom": '<"top"i>rt<"bottom"flp><"clear">'
I tried to change " by ' and use escape characters but no way.
This script in my html page, doesnt work:
$(document).ready(function() {
$("#mensuales").DataTable({
"dom": '<"top"i>rt<"bottom"flp><"clear">',
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json"
},
"lenghtMenu": [
[5, 12, 15, 20, -1],
[5, 12, 15, 20, "Todos"]
],
"ordering": true,
stateSave: true
});
});
Allan says the code is correct, but I not be able to use in my pages.
UPDATE 2
Any suggestions?
Thanks
Try with:
<script type="text/javascript" th:inline="javascript">
/*<![CDATA[*/
$(document).ready(function() {
$("#mensuales").DataTable({
"dom": '<"top"i>rt<"bottom"flp><"clear">',
"language": {
"url": "//cdn.datatables.net/plug-ins/1.10.15/i18n/Spanish.json"
},
"lenghtMenu": [
[5, 12, 15, 20, -1],
[5, 12, 15, 20, "Todos"]
],
"ordering": true,
stateSave: true
});
});
/*]]>*/
</script>

Linq to XML query to SQL

UPDATE:
I've turned my xml into a query table in coldfusion, so this may help to solve this.
So my data is:
[id] | [code] | [desc] | [supplier] | [name] | [price]
------------------------------------------------------
1 | ABCDEF | "Tst0" | "XYZ" | "Test" | 123.00
2 | ABCDXY | "Tst1" | "XYZ" | "Test" | 130.00
3 | DCBAZY | "Tst2" | "XYZ" | "Tst2" | 150.00
Now what I need is what the linq to xml query outputs below. Output should be something like (i'll write it in JSON so it's easier for me to type) this:
[{
"code": "ABCD",
"name": "Test",
"products":
{
"id": 1,
"code": "ABCDEF",
"desc": "Tst0",
"price": 123.00
},
{
"id": 2,
"code": "ABCDXY",
"desc": "Tst1",
"price": 130.00
}
},
{
"code": "DCBA",
"name": "Tst2",
"products":
{
"id": 3,
"code": "DCBAZY",
"desc": "Tst2",
"price": 150.00
}
}]
As you can see, Group by the first 4 characters of 'CODE' and 'Supplier' code.
Thanks
How would i convert the following LINQ to XML query to SQL?
from q in query
group q by new { Code = q.code.Substring(0, 4), Supplier = q.supplier } into g
select new
{
code = g.Key.Code,
fullcode = g.FirstOrDefault().code,
supplier = g.Key.Supplier,
name = g.FirstOrDefault().name,
products = g.Select(x => new Product { id = x.id, c = x.code, desc = string.IsNullOrEmpty(x.desc) ? "Description" : x.desc, price = x.price })
}
Best i could come up with:
SELECT c, supplier, n
FROM products
GROUP BY C, supplier, n
Not sure how to get the subquery in there or get the substring of code.
ps: this is for coldfusion, so I guess their version of sql might be different to ms sql..
The easiest way is to attache a profiler to you database and see what query is generate by the linq-to-SQL engine.