line graph Tickmarks and grid vertical lines are not aligned? - rgraph

Okay. i have this problem in line graph. Tickmarks(data-points) are not aligned with vertical grid lines. is there a way to achieve that.please help?

you number of tick marks need to match the number of vlines. What I often do is I will get the count of my labels variable (with javascript) and so something like this.
var numTicks = labelVariable.length;
Then on draw of the graph
options: {
numxticks: num_ticks
}

var xticks = 10;
or with php
var xticks = "<php echo $yourvariable ;?>";
var line = .......
.set('chart.numxticks',xticks)

Related

multiple matplotlib chart using loop

I need to draw multiple matploblib chart using a for loop.
I have a data from with multiple column of data points and a time series 'year'. I need to create chart for each column.
I have the following code:
df=pd.DataFrame({'Time':['2014','2015','2016','2017','2018','2019'],
'A':[1,8,3,10,5,6],
'B':[2,3,5,2,3,5],
'C':[7,4,12,11,8,1],
'D':[3,4,2,2,7,7]})
x_pos=range(len(df['Time']))
m,c = np.polyfit(x_pos,df['A'],1)
plt.scatter(x=x_pos,y='A',data=df)
plt.plot(x_pos,m*x_pos+c,'--r')
any help is appreciated
I was able to figure it out. I used the matplotlib.gridspec to achieve this.
Following is the solution:
df=pd.DataFrame({'Time':['2014','2015','2016','2017','2018','2019'],
'A':[1,8,3,10,5,6],
'B':[2,3,5,2,3,5],
'C':[7,4,12,11,8,1],
'D':[3,4,2,2,7,7]})
#import gridspec to fit subplots
import matplotlib.gridspec as gridspec
fig = plt.figure(figsize=(10,10))
# set grid size 2*2
ggpec = gridspec.GridSpec(2, 2)
getaxs = []
datacolumns = list(df[['A','B','C','D']])
for i,j in zip(datacolumns,range(1,len(datacolumns)+1)):
xpos=range(len(df['Time']))
getaxs.append(fig.add_subplot(ggpec[j - 1]))
m,c = np.polyfit(x_pos,df['A'],1)
getaxs[-1].scatter(x=xpos,y=i,data=df)
getaxs[-1].plot(x_pos,m*x_pos+c,'--r')
plt.show()
The final result will be something like following:

Google Apps Script Replace and update cell within a range

I have a Google spreadsheet that I'm trying to remove the word "woo" within a range of cells
So far I've managed to loop through the results and log the results, however I haven't figured how to update that information in the spreadsheet itself.
Any guidance would be welcomed
Thank you
function myFunction () {
var ss = SpreadsheetApp.getActiveSheet().getRange('B:B')
var data = ss.getValues();
for (var i = 0; i < data.length; i++) {
var text = data[i].toString();
var finaltext = text.replace(/woo/g, "");
data[i] = finaltext;
Logger.log(data[i]);
}
}
Use setValues()
Notes:
Usually ss is used as a shorthand for spreadsheet, as it's used on the code for a range it's better to use range as a variable name.
setValues() returns a 2D array, so data[i] returns an array of row values rather than a cell value. To get/set cell values, use data[i][0] notation.
Considering the above replace
var ss = SpreadsheetApp.getActiveSheet().getRange('B:B')
by
var range = SpreadsheetApp.getActiveSheet().getRange('B:B')
then add the following line after the for block.
range.setValues(data);
Regarding text var declaration, replace
var text = data[i].toString();
to
var text = data[i][0].toString();
Using open ended references like B:B could lead to problems. To avoid them be sure to keep the sheet rows at minimum or better instead of using an open ended reference use something like B1:B10.

Store formatting information in an array then apply it to a range

I'm trying to create a script that will automatically format a selection based on the formatting of a table in another sheet. The idea is that a user can define a table style for header, rowOdd and rowEven in the Formats sheet, then easily apply it to a selected table using the script.
I've managed to get it working, but only by applying one type of formatting (background colour).
I based my code for reading the code into an array on this article.
As you will hopefully see from my code below, I am only able to read one formatting property into my array.
What I would like to do is read all formatting properties into the array, then apply them to the range in one go. I'm new to this so sorry if my code is a mess!
function formatTable() {
var activeRange = SpreadsheetApp.getActiveSpreadsheet().getActiveRange(); //range to apply formatting to
var arr = new Array(activeRange.getNumRows());
var tableStyleSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Formats"); //location of source styles
var tableColours = {
header: tableStyleSheet.getRange(1, 1, 1).getBackground(),
rowEven: tableStyleSheet.getRange(2, 1, 1).getBackground(),
rowOdd: tableStyleSheet.getRange(3, 1, 1).getBackground()
}
for (var x = 0; x < activeRange.getNumRows(); x++) {
arr[x] = new Array(activeRange.getNumColumns());
for (var y = 0; y < activeRange.getNumColumns(); y++) {
x == 0 ? arr[x][y] = tableColours.header :
x % 2 < 1 ? arr[x][y] = tableColours.rowOdd : arr[x][y] = tableColours.rowEven;
Logger.log(arr);
}
}
activeRange.setBackgrounds(arr);
}
Thanks!
I might be wrong but based from the list of methods given in Class Range, feature to save or store formatting details currently do not exist yet.
However, you may want to try using the following:
copyFormatToRange(gridId, column, columnEnd, row, rowEnd) or copyFormatToRange(sheet, column, columnEnd, row, rowEnd) wherein it copies the formatting of the range to the given location.
moveTo(target) wherein it cuts and paste (both format and values) from this range to the target range.
Did you know that you can get all of the different formatting elements for a range straight into an array?
E.g.
var backgrounds = sheet.getRange("A1:D50").getBackgrounds();
var fonts = sheet.getRange("A1:D50").getFontFamilies();
var fontcolors = sheet.getRange("A1:D50").getFontColors();
etc.
However, there's no way to get all of the formatting in one call unfortunately, so you have to handle each element separately. Then you can apply all of the formats in one go:
targetRng.setFontColors(fontcolors);
targetRng.setBackgrounds(backgrounds);
and so on.

How to avoid x axis changed when add marks?

I have a problem to consult,when I use the Line of the Point style and show the marks, the x axis would have a problem.When annotate the code (lineSeries5.Add(5, 1,"ghgh");),the x axis shows normally like number 1,2.....,but when I use this code (lineSeries5.Add(5, 1,"ghgh"); ), the x axis becomes 'ghgh',I wonder if how to solve this problem. My purpose is showing the contents which I want to shows in the marks,but the x axis should not be changed. Waiting for your help, thank you very much!
private Steema.TeeChart.WPF.Styles.Points lineSeries5;
this.lineSeries5 = new Steema.TeeChart.WPF.Styles.Points();
this.tChart1.Series.Add(this.lineSeries5);
lineSeries5.Marks.Visible = true;
lineSeries5.Marks.Transparent = true;
lineSeries5.Pointer.Style = Steema.TeeChart.WPF.Styles.PointerStyles.Nothing;
**lineSeries5.Add(5, 1,"ghgh");**
lineSeries5.Add(9, 3);
If you want in your axis labels are values instead of labelsText, you must change the Axis labels style as I do in next line:
tChart1.Axes.Bottom.Labels.Style = AxisLabelStyle.Value;
Could you tell us if previous code solve your problem?
Thanks,

Extjs 4.2: How to set the value of grid

I have a grid for terminals, What I want to do now is to display the selected terminals into another grid. I am able to get the selected terminals with this code:
var sel = scope.getTerminalGrid().getSelectionModel().getSelection();
var user = scope.getProfinfo().getForm().getValues();
for(var i=0; i < sel.length; i++)
{
var terminals = sel[i].data;
}
You can simply get the data (in your case above its the 'sel' variable) and then load it in the second grid store.
Something like that:
var sel = scope.getTerminalGrid().getSelectionModel().getSelection();
var selRecords = sel.getSelection();
var secondGrid = scope.getMySecondGrid();
var secondStore = secondGrid.getStore();
secondGrid.removeAll(); //Clear the data
secondGrid.add(selRecords);
Of course, I separated all in a lot of variables, you can abstract some of them.
you can do it multiple ways, one is with a drag and drop grid group, another is grabbing the grid of second store like so .
var secondGrid = scope.getMySecondGrid()
secondGrid.getStore()
the store is the powerful underlying data structure of the grid. You can then load any data you want in there.

Resources