How to set name on X axis Using charts on Swift 4? - charts

This is my inquiry (edited):
I try to plot a monthly graphic using Charts, but I face some difficulties to put the names of the months on the X axis. My default value is like in the next image:
default value
And after using the most upvoted answer from here, I got this
So after investing some hours with futile results I'd like to ask you if you know how to get a plot similar to this one, please. So to summarize:
Put the names of the months on the x axis (Vertical, not horizontal as in the figure)
Plot the months' names on the base of the graphic, not on the top as seen on the default value
Thanks in advance. If you need some of my code, I can share it with you.
Kind regards.

After playing around and with a better research, this is the answer to my questions:
//Give the value of the months to the x axis
barChart.xAxis.valueFormatter = IndexAxisValueFormatter(values:months)
barChart.xAxis.granularity = 1
//Position of the x axis, rotation of the labels on the x axis and show all the names of the months consecutively
barChart.xAxis.labelPosition = XAxis.LabelPosition.bottom
barChart.xAxis.labelRotationAngle = -90.0
barChart.xAxis.setLabelCount(counter, force: false)

Related

How to create non time based HeatMap in grafana?

I have coordinates x and y, how much time ( in milliseconds) the user spent in each dot/coordinate and the time he visited that dot.
Can I create a HeatMap in Grafana where the axes are x and y and the color is based on time spent on that dot?
I don't think there's a good way to do this in any of Grafana's standard templates. You might be able to find a way with one of their plugins (maybe the Bubble Chart?), but none of them look like they do exactly what you're looking for.
https://grafana.com/plugins?type=panel

How Do I Keep All Series Labels on a 3D chart

Suppose that I have a list of 40 planets (OK some are from another solar system). Astronomers have counted the number of meteors hitting the planets from January to December. So I have 40 rows of 12 columns of data.
When I plot a 3D chart the planets are displayed on the depth axis, the months January to December are on the Category axis, and the number of meteors on the value axis.
But some of the planets are missing. It seems SpreadsheetGear or Excel is treating the planets like numbers.
How do make SpreadsheetGear display all planets on the depth axis?
PS. I reviewed all related Spreadsheetgear docs but I couldn't find how to do this and checked StackOverflow for related questions but didn't find any.
Thanks, CoolBreeze
I think I solved my own problem:
1) I increased the width of the chart when I called AddChart:
ChartObj = m_WorksheetObj.Shapes.AddChart(Left, Top, Width, Height).Chart
2) I set TackLabelSpacing = 1
Dim DepthAxis As IAxis = ChartObj.Axes(AxisType.Series)
DepthAxis.TickLabelSpacing = 1
I'm not sure if that is the best solution but it appears to work for me at the moment.
If I add more planets the labels will be closer together and it'll be harder to read the labels. I'll have to widen the chart some more to spread out the labels to make them easier to read.
I added numbers in front of the planet names so when I looked at the list of planets on the chart I could see 1-40 and I knew all planets were listed.

How to set my column at the center of the chart with ShinobiCharts

I have this column chart that has 2 modes, monthly visualization and yearly visualization, the monthly visualization works just fine with many column, however, my yearly visualization is broken because i can't get the only column that appears to be on the center of the chart, it's always being set to the first point on my XAxis.
If I were using a NumberAxis it would be easy to solve, just set the column to the middle point (in this case, position 6 among the total of 12 months). However I'm using CategoryAxis, since it isn't ordered as NumberAxis is, I'm unable to use the same solution....
How can I achieve this result with a CategoryAxis ?
PS: No matter the SChartRange I set to this Axis, the column will always be set to the first position in the XAxis.
Found a way to achieve the result I wanted.
I've altered the range to be around the first dataPoint only, this way the column got placed in the middle of the chart without having to be the "middle dataPoint", being the ONLY dataPoint. The code goes into my sChart: dataPointAtIndex forSeriesAtIndex as follows
-(id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(int)dataIndex forSeriesAtIndex:(int)seriesIndex{
.
.
.
SChartNumberRange * numberRange;
if(isYearlyChart){
numberRange = [[SChartNumberRange alloc] initWithMinimum:[NSNumber numberWithFloat:-0.9]andMaximum:[NSNumber numberWithInt:(1)]];
}
The normal NumberRange I was using was from 1 through 13.
Hope this helps others with similar problems regarding this subject :)
PS: I'll mark this as the correct answer as soon as possible.

Stair plot to vertical bar plot in Matlab

I want to create a vertical bar plot. This is my code:
bar (x, sensiv);
title ('Promedio X')
xlabel('Nm')
ylabel('Refl.')
The problem is it looks like a stair plot. I've tried to add (x,sensiv, 'stacked') but it doesn't work. It looks grouped, as you can see in the next image:
graph http://imageshack.us/a/img689/9449/capturawv.jpg
I think it's because of x-axis but I couldn't change it. How can I do it? Does somebody knows how can I do it?
EDIT
Thanks Colin! I've tried to zoom and I understand what you mean and I've tried with different values, as slayton and you said.
I think that maybe it's the way I've code the plot, it is possible?
abc=0;
for p=(61:201)
abc(p)=out1_c;
end
for p=(151:301)
abc(p)=out2_c;
end
for p=(231:380)
abc(p)=out3_c;
end
for p=(381:596)
abc(p)=out4_c;
end
for p=(1152:1531)
abc(p)=out5_c;
end
for p=(1651:2051)
abc(p)=out7_c;
end
for p=(2052:2151)
abc(p)= 0;
end
The default value for the width of the bars in a bar plot is 0.8, so given that you're not currently specifying the width, you should have gaps in between each bar. This is going to sound really obvious, but have you tried zooming in on the bar plot that is created? For some datasets, the bar function will return a plot that looks like a stair plot, but in fact has gaps if you zoom in far enough. If this is the case, then you should be able to get the gaps you want by tinkering with the width parameter as suggested by slayton.
EDIT
Okay. First things first. If you want to post additional information, you should add it to your question, NOT post it as a new answer! You can do this by clicking the edit button just below where your question is on the page. To make things more readable, you might preface your edit with a capitalized bold-face heading "EDIT" as I have done here. If you are able, try now to move the additional information you've given back into your question, and then delete the answer.
Second, I have to be honest, the additional information you posted was somewhat confusing. However, I think I understand what you want now. You want 7 bars coming up to the heights out1_c, out2_c, ..., out7_c (variable names taken from your additional information) with a small gap between each bar, and the x-axis to reflect (approximately) the intervals 450-550, 550-650, etc.
Well, if you want 7 bars, then you want your input to only have seven elements. Set:
y = [out1_c; out2_c; out3_c; out4_c; out5_c; out6_c; out7_c];
y now gives you the heights your bars will come up to on the y-axis. To locate the bars on the x-axis, define a vector x that also has seven elements, where each element gives the midpoint of where you want the bar to be on the x-axis. For example:
x = [100; 200; 300; 400; 500; 600; 700];
Then just use bar(x, y). This should get you started.
A final point on the code you posted, you can actually completely avoid the loops: read up on vectorization. But if you are going to insist on loops, the first and most important rule is to preallocate your vectors/matrices. In your code abc starts out as a scalar (a 1 by 1 matrix), but then for every p, you are adding an element at index p. What is actually happening in the background is for every p, matlab is scrapping the current abc you have in memory, and building it again from scratch with the additional element. As you might expect, this will slow down your code by many orders of magnitude.
You can set the width of the individual bars by passing a value between 0 and 1 to bar. Passing 1 indicates that there should be no space between the bars
bar(x,y,1)
Passing anything less than 1 will reduce the bar sizes and introduce spacing between the individual bars
bar(x,y,.5)

Sigmaplot: How to scale x-axis for correctly displaying boxplots

I want to display overlapping boxplots using Sigmaplot 12. When I choose the scale for the x-axis as linear then the boxes do indeed overlap but are much too thin. See figure below. Of course they should be much wider.
When I choose the scale of the x-axis to be "category", then the boxes have the right width, but are arranged along each single x-value.
I want the position as in figure 1 and the width as in figure 2. I tried to resize the box in figure 1 but when I choose 100% in "bar width" than it still looks like Figure 1.
many thanks!
okay, I found the answer myself. In Sigmaplot, there is often the need to prepare "style"-columns, for example if you want to color your barcharts, you need a column that holds the specific color names.
For my boxplot example I needed a column that has the values for "width". These had to be quite large (2000) in order to have an effect. Why ? I have no idea. First I thought it would be because of the latitude values and that the program interprets the point as "1.000"s, but when I changed to values without decimals, it didnĀ“t get better.
Well, here is the result in color.
Have fun !