I have a google line chart and the problem is, it does not start at 0 on the x-axis. I've seen this thread, but the solution seems to work only if x-values are numeric. Mine are not, unfortunatly.
Does anbody know how to resolve this? Maybe it's a problem related to the way I fill the chart with data, this is how I add the columns and rows:
tdata.addColumn('string', data[0][0]);
for (var i = 1; i < cols; i++) {
tdata.addColumn('number', data[0][i]);
}
tdata.addRows(data.length);
for (var i = 1; i < data.length; i++) {
tdata.setCell(i, 0, data[i][0]);
for (var j = 1; j < cols; j++) {
var value = parseInt(data[i][j]);
tdata.setCell(i, j, value);
}
}
And the data I feed to this is in this format:
{ "", "Kasse", "Anleihen", "Fonds", "Futures", "Optionen", "Aktien" } [Column names]
{ "01.02.2012", "10", "12", "23", "10", "12", "23" }
Related
I have a problem when I'm trying to a loop in a DataTable that a dataset contains.
I'm doing a loop like this:
for(int i = 0; i<ds.Tables[0].Rows.Count - 1 ; i++)
The problem is that I can't get the value of the last line with this one, but if I try to get rid of the "-1" and do a loop on the whole table, I'll have an out of range exception.
This out of range exception is because I have to check if the value of a line "i" is equal to the value of a line "i+1", like this:
if (ds.Tables[0].Rows[i]["Release_No"] != ds.Tables[0].Rows[i + 1]["Release_No"])
So if I do it in a loop, when the index is on the last line it will check if the last line is equal to i+1, and it's out of the table.
So I was trying to check if the index is on the last line, then just get the value of the last line, but it seems like it doesn't work.
if(ds.Tables[0].Rows.IndexOf(ds.Tables[0].Rows[i]) == ds.Tables[0].Rows.Count)
If anyone has an idea, let me know, and of course if it is not clear enough let me know, I'll give more information and more code.
Thanks for your help and your time!
Check if it's the last record, first.
I like to refactor code to read as close to sentence form as possible, explaining what you want it to do using named variables and methods, and that often gets me unlocked.
Try to make each line of code do one thing, and one thing only, like check if it is the last row:
var data = ds.Tables[0].Rows;
var lastRow = data.Count - 1;
for(int i = 0; i < lastRow ; i++)
{
if (i == lastRow){
// This is the last row. Handle the last row here.
}
else
{
// Handle all other rows here
var currentRecord = data[i];
var nextRecord = data[i + 1];
if (currentRecord["Release_No"] != nextRecord["Release_No"])
{
// Handle unique Releases...
}
}
}
Use less than or equal to like this
for(int i = 0; i<=ds.Tables[0].Rows.Count - 1 ; i++)
I hope this may get what you want.
Something like this is better ?
var lastRow = data.Count - 1;
var data = ds.Tables[0].Rows;
for(int i = 0; i< lastRow; i++)
{
testFirstCum = Convert.ToInt32(ds.Tables[0].Rows[i]["EDI_Accum_Quantity"]);
if ( i == lastRow)
{
if (DBNull.Value.Equals(data[i]))
{
quantity = 0;
}
else
{
quantity = Convert.ToInt32(data[i]);
testFirstCum = testFirstCum + quantity;
System.Diagnostics.Debug.WriteLine(quantity);
System.Diagnostics.Debug.WriteLine(testFirstCum);
}
}
else
{
var col = ds.Tables[0].Columns;
var currentRecord = data[i];
var nextRecord = data[i + 1];
if(currentRecord["Release_No"] != nextRecord["Release_No"])
{
for (int j = col[2].Ordinal; j < col.Count; j++)
{
if (DBNull.Value.Equals(data[i][j]))
{
quantity = 0;
}
else
{
quantity = Convert.ToInt32(data[i][j]);
testFirstCum = testFirstCum + quantity;
System.Diagnostics.Debug.WriteLine(quantity);
System.Diagnostics.Debug.WriteLine(testFirstCum);
}
}
}
}
}
Can someone explain to me why the answer to this problem isn't 25,102?
For the following code, suppose the if statement is true 50% of the time. If so, how many assignment operations occur? (Don't forget to count the initializations of i and j. Also remember that i++ and j++ are assignments.)
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (arr[j] < arr[i]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
I can see how you got 25102, but I think you've not counted the j loop properly - it doesn't just add one j=0 to the total because the whole loop happens multiple times.
This would have been easier if the COUNTIF function works with cell colors. I have two columns, one is text and one is just a cell colour. It only counts if the text in the first column matches the required colour (yellow in this case).
//yellow AIMS is "#ffd966"
// red to be raised is "#ff0000"
function countCellBGColour(coc, rangeSpecification) {
var color = "#ffd966";
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var backGroundColors = sheet.getRange(rangeSpecification).getBackgrounds();
var cocsheet = sheet.getRange("Sheet1!E:E");
var x = 0;
for (var i = 0; i < backGroundColors.length; i++) {
for (var j = 0; j < backGroundColors[0].length; j++) {
if(backGroundColors[i][j] == color && cocsheet == coc)
{ x++ }
}
}
return x;
}
Suppose I have a JMH test with two parameters:
#Param( { "1", "2", 4", "8", "16" } )
int param1;
#Param( { "1", "2", 4", "8", "16" } )
int param2;
Is there an idiomatic way to add a constraint on the parameters, e.g. only to benchmarks for param1 < param2?
Throwing an exception from an #SetUp works, but adds noise to the output.
Nope, not at this point. If you feel the annotations are constraining, you can always fall back to the API. There, you can do something like:
for (int p1 = 1; p1 <= 16; p1 *= 2) {
for (int p2 = 1; p2 <= p1; p2 *= 2) {
Options opt = new OptionsBuilder()
...
.param("param1", p1)
.param("param1", p2)
.build();
RunResult r = new Runner(opt).runSingle();
... put r somewhere to process
}
}
(Maintainer's perspective: it does not seem worthwhile to wind up a full-fledged annotation-based DSL for JMH, it's just simpler to let users code their advanced scenarios in Java).
UPD: Come to think about it, you can probably encode both parameters into a single #Param, if you want to stay with the annotation-only way.
I have a problem with filling a LinkedHashMap with GregorianCalendar-Objects.
I creat a GregorianCalendar starttime. Then I fill it into an ArrayList and add 200 Milliseconds 50 times. After that, I fill these values in a Map together with a double from another ArrayList. When I make a System out of the Map it only gives me the last value of the time list but all values from the double list.
starttime = new GregorianCalendar(2013, 0, 1, 13, 0, 0);
starttime.set(Calendar.MILLISECOND, 0);
GregorianCalendar time = new GregorianCalendar();
time.setTimeInMillis(starttime.getTimeInMillis());
for (int i = 0; i < 50; i++) {
time.add(Calendar.MILLISECOND, 200);
timeList.add(time.getTimeInMillis());
}
for (int i = 0; i < 50; i++) {
time.setTimeInMillis(timeList.get(i));
inputMap.put(time, valueList.get(i));
}
for (Entry<GregorianCalendar, Double> entry : inputMap.entrySet()) {
System.out.println(entry.getKey().getTime().toString()+" "
+entry.getKey().get(Calendar.MILLISECOND)+ " = " + entry.getValue());
}
I found a solution. The Problem is, that time is a reference in the inputMap. So you have to create a new GregorianCalendar in the filling loop.
for (int i = 0; i < 50; i++) {
GregorianCalendar gregCal = new GregorianCalendar();
gregCal.setTimeInMillis(starttime.getTimeInMillis());
inputMap.put(gregCal, valueList.get(i));
starttime.add(Calendar.MILLISECOND, 200);
}