I am currently trying to created a stacked column chart in Excel, using arrays that I have pre-built. The arrays do not reference any ranges on a sheet, but rather represent calculations of that data.
The issue I am having is when creating the stacked column chart, the data is not vertically stacked on the same column, but rather the second data set is stacked vertically adjacent to the first data set. I will attach an image further down but for now let me show you my code, please not that in this sub routine I actually create 4 different charts, but only one of them needs to be a stacked column, so I will reference the stacked column code below:
Sub buildCharts()
Dim myChart as Shape
Set myChart = wsRawData.Shapes.AddChart2(Left:=792, Top:=0, Width:=264, Height:=192)
With myChart.Chart
'load the data
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = myArray1
.SeriesCollection.NewSeries
.SeriesCollection(2).Values = myArray2
.SeriesCollection.NewSeries
.SeriesCollection(3).Values = myArray3
'x-axis
.SeriesCollection(1).XValues = Array("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D")
'set the chart type
.FullSeriesCollection(1).ChartType = xlColumnStacked
.FullSeriesCollection(1).AxisGroup = 1
.FullSeriesCollection(2).ChartType = xlColumnStacked
.FullSeriesCollection(2).AxisGroup = 1
.FullSeriesCollection(3).ChartType = xlLine
.FullSeriesCollection(3).AxisGroup = 1
.FullSeriesCollection(3).Format.Line.Weight = 1.25
'edit
.ChartStyle = 209
.HasTitle = True
.chartTitle.Text = "My Chart"
.ChartArea.Font.Color = vbWhite
.ChartArea.Interior.ColorIndex = 1
.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.Axes(xlCategory).MajorGridlines.Delete
End With
End Sub
Here is an image of the output of the above code:
As you can see how the columns have been stacked incorrectly.
Now, when I use the "Record Macro" function under the developer tab I get the below code:
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).AxisGroup = 1
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnStacked
And when creating a chart manually with data it creates the chart perfectly stacked.
So I am not sure what I am missing with this one. I have done some digging on the web but have been unable to find anything and am hoping someone here can give me a better understanding!
Thanks in advance.
I slightly changed and your code (I am working in Excel 2007)
Dim myChart As Shape
'changed addchart2 to addchart and sheet name, left etc
Set myChart = Sheet1.Shapes.AddChart(Left:=92, Top:=0, Width:=264, Height:=192)
With myChart.Chart
'load the data
.SeriesCollection.NewSeries
.SeriesCollection(1).Values = Array(100, 70, 120, 80, 40, 150, 200, 140, 150, 90, 110, 50)
.SeriesCollection.NewSeries
.SeriesCollection(2).Values = Array(100, 70, 120, 80, 40, 150, 200, 140, 150, 90, 110, 50)
.SeriesCollection.NewSeries
.SeriesCollection(3).Values = Array(150, 120, 150, 120, 80, 180, 280, 180, 195, 130, 160, 150)
'x-axis
.SeriesCollection(1).XValues = Array("J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D")
'set the chart type
' used .SeriesCollection instead of .FullSeriesCollection
.SeriesCollection(1).ChartType = xlColumnStacked
.SeriesCollection(1).AxisGroup = 1
.SeriesCollection(2).ChartType = xlColumnStacked
.SeriesCollection(2).AxisGroup = 1
.SeriesCollection(3).ChartType = xlLine
.SeriesCollection(3).AxisGroup = 1
.SeriesCollection(3).Format.Line.Weight = 2.25
'edit
'.ChartStyle =209 ' commented out chart style
.HasTitle = True
.ChartTitle.Text = "My Chart"
.ChartArea.Font.Color = vbWhite
.ChartArea.Interior.ColorIndex = 1
.HasLegend = True
.Legend.Position = xlLegendPositionBottom
.Axes(xlCategory).MajorGridlines.Delete
End With
End Sub
and it is producing this chart
will be pleased if it helps you
Related
I have trained a keras model with 6 classes for CNN Image Recognition. Then, I converted it to tensorflowjs using this command:
tensorflowjs_converter --quantization_bytes 1 --input_format=keras {saved_model_path} {target_path}
which then gives me 2 files (model.json, group1-shard1of1.bin). After adding it to my react native project and test the prediction function, it always returns the same result. I am converting my image to tensor base on this github thread:
const processImagePrediction = async (base64Image: any) => {
const fileUri = base64Image.uri;
const imgB64 = await FileSystem.readAsStringAsync(fileUri, {
encoding: FileSystem.EncodingType.Base64,
});
const imgBuffer = tf.util.encodeString(imgB64, 'base64').buffer;
const raw = new Uint8Array(imgBuffer);
let imageTensor = decodeJpeg(raw);
const scalar = tf.scalar(255);
imageTensor = tf.image.resizeNearestNeighbor(imageTensor, [224, 224]);
const tensorScaled = imageTensor.div(scalar);
//Reshaping my tensor base on my model size (224, 224)
const img = tf.reshape(tensorScaled, [1, 224, 224, 3]);
console.log("IMG: ", img);
const results = model.predict(img);
let pred = results.dataSync();
console.log("PREDICTION: ", pred);
}
I was expecting to have a different result but no matter what image I capture it always returns this result:
LOG IMG: {"dataId": {"id": 23}, "dtype": "float32", "id": 38, "isDisposedInternal": false, "kept": false, "rankType": "4", "scopeId": 6, "shape": [1, 224, 224, 3], "size": 150528, "strides": [150528, 672, 3]} LOG PREDICTION: [-7.7249579429626465, 4.73449182510376, 2.609705924987793, 20.0458927154541, -7.944214344024658, -18.101320266723633]
The numbers somehow change slightly but it retains the highest prediction (which is class number 4).
P.S. I'm new to image recognition so any tips would be appreciated.
I would appreciates some help from someone who knows what they are doing as opposed to me with Arrays in Swift for Xcode.
I have an array of over 40+ heart rate readinsg that I get from an Apple Watch and want to make a new array of only exactly 40 to show on a graph, but they have to be in order, I don't want them to be out of order, so I can't use random or shuffle and get the first 40 or the last 40 of the doubles.
e.g. heartratereadings = [56.0, 57.0, 58.0 ... 101.0]
var fortyReadings = ??heartratereading.somthing to get 40 values in the order they were in?
What is a way I can do that? Thanks in advance ~ Kurt
Thanks you for the solution below I was able to great a cute graph on the watch that shows heart rate readings over time by using 40 instances of a line that is 200px hight. Then I use the individual heart rate to set the heights of each of the 40 bars. Looks great, obviously nt meant for any scientific or medical purpose, just gives me a rough idea of how the heart rate changes over given time. Apples simulator only gives heart rate readings from 58-62 so I can't wait to test. Thank you!!
This is similar to what #staticVoidMan suggested. Instead of recursion, the indices of the new (smaller) array are mapped to indices of the old (larger) array via linear interpolation:
extension Array {
/// Return a smaller array by picking “evenly distributed” elements.
///
/// - Parameter length: The desired array length
/// - Returns: An array with `length` elements from `self`
func pick(length: Int) -> [Element] {
precondition(length >= 0, "length must not be negative")
if length >= count { return self }
let oldMax = Double(count - 1)
let newMax = Double(length - 1)
return (0..<length).map { self[Int((Double($0) * oldMax / newMax).rounded())] }
}
}
Examples:
let doubleArray = [56.0, 57.0, 58.0, 98.0, 101.0, 88.0, 76.0]
print(doubleArray.pick(length: 5))
// [56.0, 58.0, 98.0, 88.0, 76.0]
let intArray = Array(1...10)
print(intArray.pick(length: 8))
// [1, 2, 4, 5, 6, 7, 9, 10]
For starters, this basic extension on Array adds the functionality to return alternate elements from any type of array:
extension Array {
func evenlySpaced(length: Int) -> [Element] {
guard length < self.count else { return self }
let takeIndex = (self.count / length) - 1
let nextArray = Array(self.dropFirst(takeIndex + 1))
return [self[takeIndex]] + nextArray.evenlySpaced(length: length - 1)
}
}
Example 1:
let doubleArray = [56.0, 57.0, 58.0, 98.0, 101.0, 88.0, 76.0]
print(doubleArray.evenlySpaced(length: 5))
[56.0, 57.0, 58.0, 98.0, 101.0, 88.0, 76.0]
evenly spaced would give:
[56.0, 57.0, 58.0, 101.0, 76.0]
Example 2:
let intArray = (1...1000).map { $0 }
print(intArray.evenlySpaced(length: 40))
This shows that if you had an array of 1000 elements, the chosen interval values would be:
[25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400, 425, 450, 475, 500, 525, 550, 575, 600, 625, 650, 675, 700, 725, 750, 775, 800, 825, 850, 875, 900, 925, 950, 975, 1000]
It's a simple implementation and you could loosely say it's evenly spaced because it tends to favour the initial elements in data sets that are small when compared to the requested length.
Example 3:
let array = (1...10).map { $0 }
print(array.evenlySpaced(length: 8))
[1, 2, 3, 4, 5, 6, 8, 10]
You could instead implement a more balanced logic but the general idea would be the same.
Here is the simplest way to do so:
var heartRateReading = [56.0, 57.0, 58.0, 98.0, ..., 101.0]
//If you want 40 items from the 10th position
var fortySelected = heartRateReading.suffix(from: 10).suffix(40)
// If you want to iterate each second and get 40 values out of it
_ = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { (_) in
let values = heartRateReading.suffix(40)
print(values)
}
To get X number of elements from Y index we can have generic function like below:
func fetchElements<T>(sourceArray: [T],
startIndex: Int,
recordCount: Int) -> [T] {
guard startIndex >= 0 && recordCount >= 0 else { return [] }
guard startIndex < sourceArray.count else { return [] }
let arrTrimmedFromStartIndex = Array(sourceArray.suffix(from: startIndex))
let arrWithRequiredCount = Array(arrTrimmedFromStartIndex.prefix(recordCount))
return arrWithRequiredCount
}
Now we can use it with any type as below:
class MyModel {
let name: String
init(name: String) {
self.name = name
}
}
Call to actual function:
let arr = (0..<10).map({ MyModel(name: "\($0)") })
let result = fetchElements(sourceArray: arr,
startIndex: 4,
recordCount: 3)
print(arr.map({$0.name}))
print(result.map({$0.name}))
Print result:
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
["4", "5", "6"]
Hope this helps!
Just use a for loop
Var forty = [double]()
For n in 1...40 {
forty.insert(heartRate[n], at: 0)
}
How can I get {{ $cSiacon->'NOME-CLIENTE' }} if it is dash separated? I´ve tried ['NOME-CLIENTE'] but Laravel gives me:
ErrorException (E_ERROR)
Cannot use object of type Illuminate\Http\JsonResponse as array
In my code:
$responseClienteSiacon = $clienteSiaconSOAP->ROS_ValidarCliente($paramClienteSiacon);
$cSiacon = response()->json(($responseClienteSiacon->ValidarCliente->Cliente));
return $cSiacon;
The result is:
[
{
"CODIGO-TIPO-PESSOA": "J",
"CPF-CNPJ": "00635344000177",
"CODIGO-GRUPO": "07384",
"NUMERO-SEQUENCIA": 0,
"NUMERO-COTA": 853,
"NOME-CLIENTE": "AUTO ESCOLA GUILHERMITTI E L LTDA",
"NUMERO-CONTRATO": 859866,
"DESCRICAO-BEM": "HONDA NXR 160 BROS",
"VALOR-BEM": 12975,
"NUMERO-TELEFONE": "017 32581859",
"DATA-PROXIMA-REUNIAO": "20190322",
"SITUACAO-COBRANCA": "N",
"DESCRICAO-SITUACAO-COBRANCA": "Normal",
"FASE-SITUACAO-COBRANCA": "N000",
"CODIGO-PLANO-COTA": 31,
"DATA-ENTREGA": "20180507",
"DATA-CONTEMPLACAO": "20170622",
"PERC-TOTAL-PAGO": 87.7196,
"PERC-TOTAL-PENDENTE": 3.1401,
"PERC-QUITACAO": 12.2804,
"CODIGO-FORMA-PAGAMENTO": 1,
"DATA-NASCIMENTO": "",
"DATA-CANCELAMENTO": "",
"CADASTRO-ATUALIZADO": "N",
"SEGMENTO-CADOC": 4,
"CEP": 15115000
},
{...
}
]
Also I´ve tried to get a higher position like: json(($responseClienteSiacon->ValidarCliente)); but the problem stils the same: the dash separated attribute name.
Should I convert each name before?
Like this
$object->{'NOME-CLIENTE'};
POC
https://3v4l.org/cTO7o
Example using blade
#php
$json = <<<JSON
[
{
"CODIGO-TIPO-PESSOA": "J",
"CPF-CNPJ": "00635344000177",
"CODIGO-GRUPO": "07384",
"NUMERO-SEQUENCIA": 0,
"NUMERO-COTA": 853,
"NOME-CLIENTE": "AUTO ESCOLA GUILHERMITTI E L LTDA",
"NUMERO-CONTRATO": 859866,
"DESCRICAO-BEM": "HONDA NXR 160 BROS",
"VALOR-BEM": 12975,
"NUMERO-TELEFONE": "017 32581859",
"DATA-PROXIMA-REUNIAO": "20190322",
"SITUACAO-COBRANCA": "N",
"DESCRICAO-SITUACAO-COBRANCA": "Normal",
"FASE-SITUACAO-COBRANCA": "N000",
"CODIGO-PLANO-COTA": 31,
"DATA-ENTREGA": "20180507",
"DATA-CONTEMPLACAO": "20170622",
"PERC-TOTAL-PAGO": 87.7196,
"PERC-TOTAL-PENDENTE": 3.1401,
"PERC-QUITACAO": 12.2804,
"CODIGO-FORMA-PAGAMENTO": 1,
"DATA-NASCIMENTO": "",
"DATA-CANCELAMENTO": "",
"CADASTRO-ATUALIZADO": "N",
"SEGMENTO-CADOC": 4,
"CEP": 15115000
}
]
JSON;
$json = json_decode($json);
#endphp
{{-- will echo "AUTO ESCOLA GUILHERMITTI E L LTDA" --}}
{{ $json[0]->{'NOME-CLIENTE'} }}
I'm using Swift to create an array that needs to match this format:
let items = [["1", "red", "33", "canada"], ["2", "blue", "66", "usa"]]
In my code, I query a database and have multiple rows returned with the pertinent info:
let items = [id+" - "+colour+" - "+number+" - "+home_location]
I use a loop to .append the array but the format comes out like this instead:
["1 - red - 33 - canada", "2 - blue - 66 - usa"]
What do I need to do to create the required array structure?
For each row of the database, instead of
let items = [id+" - "+colour+" - "+number+" - "+home_location]
say
let items = [id, colour, number, home_location]
Now append that to a var array of [[String]].
create model for your data like this
class ModelClass {
var id = ""
var colour = ""
var number = ""
var home_location = ""
}
and then create the object of your model class like this
let objmodel : ModelClass = ModelClass()
objmodel.id = "1"
objmodel.colour = "red"
objmodel.number = "33"
objmodel.home_location = "canada"
then create your main array and append this model object to your model array
var arrData = [ModelClass]()
arrData.append(objmodel)
I have a XY Line chart wherein I don't want to show the value zero eventhough the graph is plotted at the below i.e just ignorezerovalues as in stackedbar chart which works pretty good.
Update: Let me show you in detail. This is the data I have to plot where I have two ZERO values which shouldn't be displayed but plotted.
I have found a method in bar chart - setignoreZeroValues() that ignores the zeros in bar.
double data1[] = {0.0, 33.0, 44.0, 11.0, 77.0, 44.0,
55.0, 66.0, 27.0, 99.0, 122.0, 0.0};
XYSeries series1 = new XYSeries("Last year", false);
for (int i = 0; i < data1.length; i++) {
series1.add(data1[i], i);
}
XYSeriesCollection dataset = new XYSeriesCollection();
dataset.addSeries(series1);
JFreeChart chart = ChartFactory.createXYLineChart("Title", "Values",
"", dataset, PlotOrientation.HORIZONTAL, true, true, false);
chart.setBackgroundPaint(Color.LIGHT_GRAY);
XYPlot plot = (XYPlot) chart.getPlot();
String[] Cat = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"};
SymbolAxis rangeAxis = new SymbolAxis("Cat", Cat);
//rangeAxis.setTickUnit(new NumberTickUnit(1));
//rangeAxis.setRange(0,grade.length);
plot.setRangeAxis(rangeAxis);