dimple.js multi-series **line** charts - dimple.js

I'm trying to create a simple chart with two axis and two data series.
When I define bubble series - all works as expected however when both series are defined as line, the dashed lines from the data points to the y axis get confused
Surprisingly, I can't Can't seem to find any examples which show 2* y axis with 2*line series.
My x axis is time based but I can illustrate the problem using a previous JSfiddle answer (jsfiddle.net/NCW89/):
var svg = dimple.newSvg("#chartContainer", 600, 400),
chart = null,
s1 = null,
s2 = null,
x = null,
y1 = null,
y2 = null;
chart = new dimple.chart(svg);
x = chart.addCategoryAxis("x", "Fruit");
y1 = chart.addMeasureAxis("y", "Value");
y2 = chart.addMeasureAxis("y", "Value");
s1 = chart.addSeries("Year", dimple.plot.bubble, [x, y1]);
s1.data = [
{ "Value" : 100000, "Fruit" : "Grapefruit", "Year" : 2012 },
{ "Value" : 400000, "Fruit" : "Apple", "Year" : 2012 },
{ "Value" : 120000, "Fruit" : "Banana", "Year" : 2012 }
];
s2 = chart.addSeries("Year", dimple.plot.bubble, [x, y2]);
s2.data = [
{ "Value" : 110000, "Fruit" : "Grapefruit", "Year" : 2013 },
{ "Value" : 300000, "Fruit" : "Apple", "Year" : 2013 },
{ "Value" : 140000, "Fruit" : "Banana", "Year" : 2013 }
];
chart.draw();
Changing the series from dimple.plot.bubble --> dimple.plot.line will demonstrate the behaviour.
Seems such a commonly required feature that I can't help feeling that I'm missing something obvious.
Thanks

I'm afraid you aren't missing anything it's a bug introduced in a recent version. I'll fix it in version 1.2 coming out in the next week or two. Unfortunately the breaking version was also the one which added the ability to set series specific data. If you want to work around in the meantime you'll need to go back to version 1.1.3 and set your data the old fashioned way:
var svg = dimple.newSvg("#chartContainer", 600, 400),
chart = null,
s1 = null,
s2 = null,
x = null,
y1 = null,
y2 = null,
data = [
{ "Fruit" : "Grapefruit", "Value 1" : 100000, "Year 1" : 2012, "Value 2" : 110000, "Year 2" : 2013 },
{ "Fruit" : "Apple", "Value 1" : 400000, "Year 1" : 2012, "Value 2" : 300000, "Year 2" : 2013 },
{ "Fruit" : "Banana", "Value 1" : 120000, "Year 1" : 2012, "Value 2" : 140000, "Year 2" : 2013 }
];
chart = new dimple.chart(svg, data);
x = chart.addCategoryAxis("x", "Fruit");
y1 = chart.addMeasureAxis("y", "Value 1");
y2 = chart.addMeasureAxis("y", "Value 2");
s1 = chart.addSeries("Year 1", dimple.plot.line, [x, y1]);
s2 = chart.addSeries("Year 2", dimple.plot.line, [x, y2]);
chart.draw();
http://jsfiddle.net/NVV9r/1/

Related

Get sum of the values of objects in an array

I have a dataweave input as given below.
%dw 2.0
output application/json
var demo = [
{
"mat" : 1000,
"seg" : "z"
},
{
"mat" : 2000,
"seg" : "b"
},
{
"mat" : 3000,
"seg" : "x"
}
]
var count = 0
---
count
I need the sum of the "mat" field, the count should 6000. How do I achieve this ?
I did it like this
%dw 2.0
output application/json
var demo = [
{
"mat" : 1000,
"seg" : "z"
},
{
"mat" : 2000,
"seg" : "b"
},
{
"mat" : 3000,
"seg" : "x"
}
]
var count = sum(demo.mat)
---
count

How to create a map of Excel file key-value without using column name in Dataweave?

I am reading an excel file (.xlsx) into a json array and I am creating into a map because I want to apply validations to each of the column individually. I am able to access it using the column name like so,
Excel file is :
column A, column B
value of Column A, value of column B
I am accessing it like this :
payload map(item, index) ->
"Column Name A" : item."Column Name A",
"Column Name B" : item."Column Name B"
Where column A and B are the excel column header.
What I want to do is to create the same map but using the column index like
payload map(item, index) ->
item[0].key : item[0],
item[1].key : item[1]
So that I do not have to hard code the excel header name and I can rely on the index of the excel columns.
I have tried using pluck $$ to create a map of Keys but I cannot create a map of keys-value, I am not able to use item[0] as key in a map.
How can I achieve above without using excel column header name?
Expected output should be like this :
{
"Column A " : "value of Column A",
"Column B" : "value of Column B",
"Errors" : "Column A is not valid"
}
Assuming that you'd like to validate each payload item loaded from an Excel file, you could use the following DataWeave expression:
%dw 2.0
output application/json
fun validate(col, val) =
if (isEmpty(val)) {"error": col ++ ": value is null or empty"}
else {}
fun validateRow(row) =
"Errors":
flatten([] << ((row mapObject ((value, key, index) -> ((validate((key), value))))).error default []))
---
payload map (item, index) -> item ++ validateRow(item)
Using the following input payload:
[
{"col1": "val1.1", "col2": "val1.2", "col3": "val1.3"},
{"col1": "val2.1", "col2": "val2.2", "col3": null}
]
would result in:
[
{
"col1": "val1.1",
"col2": "val1.2",
"col3": "val1.3",
"Errors": [
]
},
{
"col1": "val2.1",
"col2": "val2.2",
"col3": null,
"Errors": [
"col3: value is null or empty"
]
}
]
The expression will result in an output slightly different than the one you're expecting, but this version will allow you to have an array of error messages that can be easier to manipulate later on in your flow.
One thing to keep in mind is the possibility to have more than one error message per column. If that's the case, then the DataWeave expression would need some adjustments.
Try just using the index. It should work just fine.
%dw 2.0
output application/json
---
({ "someKey": "Val1", "lksajdfkl": "Val2" })[1]
results to
"Val2"
And if you want to use a variable as a key you have to wrap it in parentheses.
EG, to transform { "key": "SomeOtherKey", "val": 123 } to { "SomeOtherKey": 123 } you could do (payload.key): payload.val
Try this:
%dw 2.0
output application/json
var rules = {
"0": {
key: "Column A",
val: (val) -> !isEmpty(val),
},
"1": {
key: "Column B",
val: (val) -> val ~= "value of Column B"
}
}
fun validate(v, k, i) =
[
("Invalid column name: '$(k)' should be '$(rules[i].key)'") if (rules[i]? and rules[i].key? and k != rules[i].key),
("Invalid value for $(rules[i].key): '$(v default "null")'") if (rules[i]? and rules[i].val? and (!(rules[i].val(v))))
]
fun validate(obj) =
obj pluck { v: $, k: $$ as String, i: $$$ as String } reduce ((kvp,acc={}) ->
do {
var validation = validate(kvp.v, kvp.k, kvp.i)
---
{
(acc - "Errors"),
(kvp.k): kvp.v,
("Errors": (acc.Errors default []) ++
(if (sizeOf(validation) > 0) validation else [])
) if(acc.Errors? or sizeOf(validation) > 0)
}
}
)
---
payload map validate($)
Output:
[
{
"Column A": "value of Column A",
"Column B": "value of Column B"
},
{
"Column A": "",
"Column B": "value of Column B",
"Errors": [
"Invalid value for Column A: ''"
]
},
{
"Column A": "value of Column A",
"Column B": "value of Column C",
"Errors": [
"Invalid value for Column B: 'value of Column C'"
]
},
{
"Column A": null,
"Column C": "value of Column D",
"Errors": [
"Invalid value for Column A: 'null'",
"Invalid column name: 'Column C' should be 'Column B'",
"Invalid value for Column B: 'value of Column D'"
]
}
]

Sort element lines by a sum VB.Net

Can i short a textbox by a sum lines? example: I have textbox:
Textbox1.Lines(0)= 1 10
Textbox1.Lines(1)= 1 11
Textbox1.Lines(2)= 2 10
Textbox1.Lines(3)= 3 11
Textbox1.Lines(4)= 2 12
Expected Output: preferably if possible, write the sum that is. with :( sum = x) preferably short by descending, probably an example of sorting code would help me, but I can do that too, but for now I don't know how to order according to the sum of the lines. just to sort them out, this would be a model, but to know the sum of each one as well.
{ LstScan = 2 12, DrwSum = 14 }
{ LstScan = 3 11, DrwSum = 14 }
{ LstScan = 2 10, DrwSum = 12 }
{ LstScan = 1 11, DrwSum = 12 }
{ LstScan = 1 10, DrwSum = 11 }
In c# this would look like:
var list = new[] { "2 12", "3 11", "2 10", "1 11", "1 10" }
.Select(o => Tuple.Create<string, int>(o, o.Split(' ').Sum(x => int.Parse(x))));
var result = list.OrderByDescending(o => o.Item2).ToList();
In vb.net it would be:
Dim list = {"2 12", "3 11", "2 10", "1 11", "1 10"}
.[Select](Function(o) Tuple.Create(Of String, Integer)(o, o.Split(" "c).Sum(Function(x) Integer.Parse(x))))
Dim result = list.OrderByDescending(Function(o) o.Item2).ToList()

Failure to match strings(Arabic) in CHAI assertion library

I have two arrays:
var array_one = [
{
"accountNo": "1",
"id" : 12,
"name" : "אוצר החייל - 14"
},
{
"accountNo": "1",
"id" : 13,
"name" : "china bank"
}
],
array_two = [
{
"accountNo": "1",
"id" : 12,
"name" : "אוצר החייל - 14"
},
{
"accountNo": "1",
"id" : 13,
"name" : "china bank"
}
];
Both the array's contents are same, but it fails to assert that the two array's have the same content. ie
array_one.should.be.deep.equal(array_two) returns false;
And the reason for failure being the matching of strings in Hebrew.
Cannot figure out a way to match Hebrew strings using CHAI assertion library.

MongoDB update sub array

I'm really new to MongoDB and am experiencing an issue with an update operation. This is the document:
"_id" : ObjectId("507d95d5719dbef170f15c00"),
"name" : "Phone Service Family Plan",
"type" : "service",
"monthly_price" : 90,
"limits" : {
"voice" : {
"units" : "minutes",
"n" : 1200,
"over_rate" : 0.05
},
"data" : {
"n" : "unlimited",
"over_rate" : 0
},
"sms" : {
"n" : "unlimited",
"over_rate" : 0
}
},
"sales_tax" : true,
"term_years" : 3
I want to update over_rate for sms in limits to 0.01 from 0. Any help will be appreciated.
try this? (first argument in update being the document you want to update)
db.objects.update({name:"something"},{"$set":{"limits.sms":{"over_rate":0.01}}})