MpAndroidChart CandleStick Showing a range with dual seekbar? - mpandroidchart

I am using a dual seekbar to select the min and max range.
It works when taking the max range down, but when pulling the min range up it fails.
The range seekbar OnRangeSekkbarChangedListener:
RangeSeekBar.OnRangeSeekBarChangeListener<Integer> skListener = new RangeSeekBar.OnRangeSeekBarChangeListener<Integer>() {
#Override
public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, Integer minValue, Integer maxValue) {
int max = bar.getSelectedMaxValue().intValue();
int min = bar.getSelectedMinValue().intValue();
mChart.resetTracking();
//Hold of actual drawing lists
List<CandleEntry> y = new ArrayList<CandleEntry>();
List<String> x = new ArrayList<String>();
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
y.add(current);
x.add(currentDate);
}
//Show less of the chart and invalidate
CandleDataSet mSet = new CandleDataSet(y, "Price");
mSet.setDecreasingColor(getResources().getColor(R.color.black));
mSet.setIncreasingPaintStyle(Paint.Style.FILL);
mSet.setIncreasingColor(getResources().getColor(R.color.accent));
mSet.setDecreasingPaintStyle(Paint.Style.FILL);
mSet.setShadowColor(getResources().getColor(R.color.black));
mCandledata = new CandleData(x, mSet);
//Don't show value text
mCandledata.setDrawValues(false);
mChart.setData(mCandledata);
mChart.invalidate();
}
};
rangeSeekBar.setOnRangeSeekBarChangeListener(skListener);
Results Sceenshots:
Initial Load:
Max Range pulled to near beginning:
Min Range pulled to near end:

You need to change the xIndex of the candle Entries. The first candle needs to have an xIndex of 0
int xIndex = 0;
for (int i = min; i < max ; i++){
//get candle entry from
CandleEntry current = yVals.get(i);
String currentDate = xVals.get(i);
//set the xIndex value
x.setXIndex(xIndex);
y.add(current);
x.add(currentDate);
xIndex++;
}

Related

How do I auto populate row data based on criteria but have return values editable?

Hello I'm brand new to the script world!
Problem: Vlookup return is not editable.
I tried IndexMatch without success.
I am making a truck maintenance file. The trucks have hour and kilometer trackers that are updated hourly in sheets. Our goal is to enter truck unit number and have the date, hours, and kilometers populate our mechanics notes. From Data entry sheet a button will enter that data into each units maintenance page. Vlookup returned the right results but if an adjustment on date, hours, or kilometers needs to be made the cell can't be edited.
I am looking for a hand in setting this up.
I will share the sheet.
Search Key 'Data Entry A2'
Range 'Data Entry A8:C17'
Index 'Data Entry A8:A17'
Thanksenter link description here
function onEdit(e)
{
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Menu");
var activeCell = sheet.getActiveCell();
var col = activeCell.getColumn();
var row = 2;
if (col == 1 ) { // update when change in column 1, adapt if neededfunction
CopyRow() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuSheet = ss.getSheetByName("Menu");
var inventorySheet = ss.getSheetByName("Inventory");
menuSheet.getRange("C2:D2").clear();
var partNumber = menuSheet.getRange(2,1).getValue();
var lastRow = inventorySheet.getLastRow() + 1;
var foundRecord = false;
for(var j = 2; j < lastRow; j++)
{
if(inventorySheet.getRange(j,1).getValue() ==partNumber)
{
var nextRow = menuSheet.getRange(2,3);
var getCopyRange = inventorySheet.getRange('B' + j + ':C' + j);
getCopyRange.copyTo(menuSheet.getRange(2, 3));
foundRecord = true;
}
}
if(foundRecord == false)
{
menuSheet.getRange(5,1).setValue(['(NO RECORDS FOUND)']);
}
}
}

EPPlus two color conditional date format

I have a column with dates and I want to conditionally color any cell that is older that 2 week yellow, and any that is older than 90 days red. I can't figure out how to do that.
Should be able to just add the conditions like any other. You can use the TODAY() function in excel and subtract:
[TestMethod]
public void Conditional_Formatting_Date()
{
//https://stackoverflow.com/questions/56741642/epplus-two-color-conditional-date-format
var file = new FileInfo(#"c:\temp\Conditional_Formatting_Date.xlsx");
if (file.Exists)
file.Delete();
//Throw in some data
var dataTable = new DataTable("tblData");
dataTable.Columns.AddRange(new[] {
new DataColumn("Col1", typeof(DateTime)),
new DataColumn("Col3", typeof(string))
});
var rnd = new Random();
for (var i = 0; i < 100; i++)
{
var row = dataTable.NewRow();
row[0] = DateTime.Now.AddDays(-rnd.Next(1, 100));
row[1] = $"=TODAY() - A{i +1}";
dataTable.Rows.Add(row);
}
//Create a test file
using (var package = new ExcelPackage(file))
{
//Make the stylesheet
var ws = package.Workbook.Worksheets.Add("table");
var range = ws.Cells[1, 1].LoadFromDataTable(dataTable, false);
ws.Column(1).Style.Numberformat.Format = "mm-dd-yy";
ws.Column(1).AutoFit();
//Add the calc check
var count = 0;
foreach (DataRow row in dataTable.Rows)
ws.Cells[++count, 2].Formula = row[1].ToString();
//Add the conditions - order matters
var rangeA = range.Offset(0, 0, count, 1);
var condition90 = ws.ConditionalFormatting.AddExpression(rangeA);
condition90.Style.Font.Color.Color = Color.White;
condition90.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition90.Style.Fill.BackgroundColor.Color = Color.Red;
condition90.Formula = "TODAY() - A1> 90";
condition90.StopIfTrue = true;
var condition14 = ws.ConditionalFormatting.AddExpression(rangeA);
condition14.Style.Font.Color.Color = Color.Black;
condition14.Style.Fill.PatternType = ExcelFillStyle.Solid;
condition14.Style.Fill.BackgroundColor.Color = Color.Yellow;
condition14.Formula = "TODAY() - A1> 14";
package.Save();
}
}
Which gives this in the output:
I am assuming that you have the column number of the date column and number of rows in your records. Also, the following loop is under assumption that the first row is your column header and records begin from second row. Change the loop counter's initialization and assignment accordingly.
int rowsCount; //get your no of rows
int dateColNumber; //Assign column number in excel file of your date column
string cellValue;
DateTime dateValue;
DateTime today = DateTime.Now;
double daysCount;
for(int i=1;i<rowsCount;i++)
{
cellValue = ws.Cells[i + 1, dateColNumber].Text.ToString(); //First row is header start from second
if(DateTime.TryParse(cellValue,out dateValue))
{
daysCount = (today - dateValue).Days;
if(daysCount>90)
{
ws.Cells[i + 1,dateColNumber].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
ws.Cells[i + 1,dateColNumber].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Red);
}
else if(daysCount>14)
{
ws.Cells[i + 1, dateColNumber].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
ws.Cells[i + 1, dateColNumber].Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Yellow);
}
}
}

Conditional Formatting With Icons Epplus

I need to achieve something like this with Epplus.
Can someone guide me with the code I need to use.
Following is the code to do exactly what you want but it is for three icon set you can change it based on your icons. I'm setting red color arrow if value is greater than 4,yellow color arrow if value is between 1 and 4 and, finally, green color if it is less than 1. Just change "AddThreeIconSet" to your icons. You should get the idea with this.
for (int j = 2; j <= 9; j++) // Loop through columns
{
for (int i = 3; i <= 12; i++) // Loop through rows
{
// gets only the current cell as range
ExcelRange rng = worksheet.Cells[i, j, i, j];
ExcelAddress address = new ExcelAddress(rng.Address);
// Get the value of the current cell
if(Convert.ToDouble(worksheet.Cells[i, j].Value) >= 4.0)
{
var v = worksheet.ConditionalFormatting.AddThreeIconSet(address, eExcelconditionalFormatting3IconsSetType.Arrows);
v.Reverse = true;
v.Icon1.Type = eExcelConditionalFormattingValueObjectType.Num;
}
else if (Convert.ToDouble(workSheet.Cells[i, j].Value) > 1.0 && Convert.ToDouble(workSheet.Cells[i, j].Value) < 4.0)
{
var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows);
v.Icon3.Type = eExcelConditionalFormattingValueObjectType.Num;
}
else if (Convert.ToDouble(workSheet.Cells[i, j].Value) < 1.0)
{
var v = worksheet.ConditionalFormatting.AddThreeIconSet(address , eExcelconditionalFormatting3IconsSetType.Arrows);
v.Icon2.Type = eExcelConditionalFormattingValueObjectType.Num;
}
}
}

Zedgraph - Change X-Axis from points to frequency

i have a working program where i can add an array to a Zedgraph and show this in a form.
Now i only want to change the display of the x-axis from points (0..400) to frequency (9e3..6e9 Hz).
Here are my currently working functions:
public void AddGraph(double[] Values, string LegendName)
{
int i = 0;
PointPairList list = new PointPairList();
for (i = 0; i < Values.Length; i++)
{
list.Add(i, Values[i]);
}
if (i > MaxXAxis)
MaxXAxis = i;
SList.Add(list);
SListColor.Add(Color.Black);
}
SListName.Add(LegendName);
}
public void ShowDiagram(string Title, string XAxisName, string YAxisName,
int Timeout_ms)
{
ZedGraph.ZedGraphControl zgc = new ZedGraphControl();
GraphPane myPane = zgc.GraphPane;
LineItem myCurve = null;
// Set the titles and axis labels
myPane.Title.Text = Title;
myPane.XAxis.Title.Text = XAxisName;
myPane.YAxis.Title.Text = YAxisName;
for (int i = 0; i < SList.Count(); i++)
{
myCurve = myPane.AddCurve(SListName[i], SList[i], SListColor[i],
SymbolType.None);
myCurve.Line.Width = 2;
}
// Add gridlines to the plot, and make them gray
myPane.XAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.XAxis.MinorGrid.Color = Color.LightGray;
myPane.YAxis.MinorGrid.Color = Color.LightGray;
myPane.XAxis.MinorGrid.DashOff = 0;
myPane.YAxis.MinorGrid.DashOff = 0;
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.XAxis.MajorGrid.Color = Color.Gray;
myPane.YAxis.MajorGrid.Color = Color.Gray;
myPane.XAxis.MajorGrid.DashOff = 0;
myPane.YAxis.MajorGrid.DashOff = 0;
// Move Legend to bottom
myPane.Legend.Position = LegendPos.Bottom;
zgc.AxisChange();
myPane.XAxis.Scale.Max = MaxXAxis;
zgc.Location = new Point(0, 0);
zgc.Size = new Size(panel_diagramm.ClientRectangle.Width, panel_diagramm.ClientRectangle.Height);
panel_diagramm.Controls.Add(zgc);
}
How can i change the above two functions that they display the frequency in the x-axis?
I already tried to change the AddGraph-function to pass the needed parameters and to calculate the list to have the correct values. But what then...?
public void AddGraph_Frequency(int **Points**, double **StartFrequency**,
double **StopFrequency**, double[] Values, string GraphColor, string LegendName)
{
...
double frequency = StartFrequency; //der erste Punkt
double Intervall = (StopFrequency - StartFrequency) / Points;
for (i = 0; i < Points; i++)
{
list.Add(frequency, Values[i]);
frequency = frequency + Intervall;
}
....
}
Thanks for any help
best regards
Solved.
Missing was:
myPane.XAxis.Scale.Max = Stopfrequency;
myPane.XAxis.Scale.Min = Startfrequency;

How do i create a calculated measure that will filter data by days overdue

I have a field in my fact table called days overdue. I would like to create a set that will do the following: If the days due is between 0 - 29, then 0 - 29 days overdue, if between 30 and 59 days old, then '30 - 59 days overdue. How would i create this?
We need to know what kind of array you're using, or linked list, or my favorite for these things, a vector, etc.
If you were using a vector, you would create your own class to be used as a datatype with things like:
Class MyData
{
String name;
int daysPastDue; // how you want to factor this is up to you,
// i suggest looking into Java.util.date or Java.util.calendar
public MyData
{
name = "";
daysPastDue = 0;
}
}
Class DoWork
{
public void myWork() // excuse the indent, forgot to put in the class name
{
vector <MyData> input;
MyData 0To29 [] = new MyData[input.size()];
MyData 33To59 [] = new MyData[input.size()];
MyData item = new MyData();
int 0To29count = 0;
int 30To59count = 0;
for (i = 0; i <= list.size(); i++)
{
item = input.elementAt(i)
if (item.daysPastDue <= 29)
{
0To29[0To29Count] = input;
0To29Count ++;
}
elseif (item.daysPastDue >= 30 && item.daysPastDue <= 59)
{
30To59[30To59Count] = input;
30To59Count ++;
}
}
}
}
then you have your 2 arrays and can output them as you wish. however i would recommend starting at daysPastDue = 100000 and decrement it and check the number through the vector until you have all the items in the vector listed. That way they're all in order from the most past due, to the least and you get the output of exactly how long they've been past due.