Format maxLabel on axis differently than other labels - echarts

I am hoping to use a different format specifically for the top axis label on my y-axis. For example, if I have a percentage value axis, I would like to see the % symbol only on the top axis label, while the rest of the labels beneath it remain formatted as numbers without a symbol.
So far, I've been using the formatter option and have created a function that receives value and index per the ECharts docs. The example link below does what I need it to do, but does it for the bottom of the axis rather than the top. I need a way to use this same logic, but select the maximum index on the axis.
Link to example in docs:
https://echarts.apache.org/en/option.html#yAxis.axisLabel.formatter
Code from example in docs:
The if (index === 0) is the logic I'm referring to
// Use callback function; function parameters are axis index
formatter: function (value, index) {
// Formatted to be month/day; display year only in the first label
var date = new Date(value);
var texts = [(date.getMonth() + 1), date.getDate()];
if (index === 0) {
texts.unshift(date.getYear());
}
return texts.join('/');
}
Here's what I've tried:
I attempted to use the index argument to figure out the max index # in my dataset, but couldn't figure out how to do that given that the function is called once per value and includes only the data for that value.
I tried passing params to the function since that's how formatter works in the series config, but it looks like that's not possible in the axis config
One (unattractive) alternative is to use the y-axis axisName to display any symbols I want to have appended to the top label, and manually position it using padding. This probably wouldn't work because I'll also need to use the axisName separately from time to time.
A Possible Hint
This might not be possible yet, but at least behind the scenes I know ECharts is able to select the top label through the showMaxLabel option in axisLabel.
Is there a way to check if a label is the maximum label in the formatter function for an axis?

Related

Map step to linear scale more than 100 with MUI Slider

I'm using MUI slider, and I'm at a loss how to create a slider with mapping for values more than 100. Apart from creating all 180 days in the mark array and restricting the values, is there another way to do it? I was hoping to be able to set something like step={1} and stepLength={100/180} which will give the distance travelled on the line per step (signifying one day).
I have this codesandbox with my not-working-correctly example.
Just had this same problem. Add
max={180}
In your
<Slider
...
min={0}
max={180}
...
/>
Then change the values under your labels inside of
const Marks = [...];
To get your desired output!
If you want to add a side button to increment by a certain amount, MUI also has an input field option.

How to make the set of possible values for UISlider an open interval?

I am using a UISlider to allow a user to choose among four options. I ask the user a question of the form "how much do you like this thing?", they respond by moving the slider, and then behind the scenes I map the value of the slider to one of four elements of an array. I want the first quarter of the slider to correspond to the first element of the array, the second quarter of the slider to correspond to the second element of the array, and so on.
By default, the range of a slider is [0,1], so one natural way to do what I want is:
let index = Int(rangedSlider.value * Float(currentAnswers.count) )
assuming that rangedSlider is the name of the outlet connected to the UISlider in question, and currentAnswers is the array of answers I'm mapping to. The issue with this is that if the user moves the slider all the way to the right, that sets the value of the slider to 1, which maps to index 4 by the formula above (assuming there are four answers). I can always add an additional line of code that takes care of that case separately,
if rangedSlider.value == 1 { index = currentAnswers.count - 1 }
but I prefer a one line solution.
I can also set the max value of the slider to 0.99 in the Storyboard and stick with the first line of code I wrote, but I want to know: is there a built-in way to make the range of UISlider values an open interval? Is there a better way to get the behavior I want?
Is this any more complicated than:
let index = Int(rangedSlider.value * Float(currentAnswers.count - 1))
Or have I misunderstood the problem you're having?
That way your index will be returned as a number between 0 and 3 with 0 corresponding to the first answer and 3 corresponding to the fourth answer.

How to put color for the whole cell

I am trying to color code my list in tableau with red color for dates in end date lesser than today() or when concern column is Yes. I created a dual axis of 1 and 0 to get the cells with color in one column and get the text in another and created a dual axis so that they overlap. For that I created a calculated column where I gave the color red if the conditions meet.
This is in my calculated field:
Color:
IF TODAY()>[End Date] OR [Concern (Yes/No)]="Yes" then "RED"
ELSE "None"
END
However even after totally maximizing the size of the square for color for 1. The fields do not fill the whole cell. How do I fill the whole cell?
Here is the pic:
Please help me out here?
You may have 2 options here. I haven't tested so will leave you to see what works best.
Option 1 - use a measure and a Square mark type. Create a calculated field that returns a measure. We can adapt the formula you have built:
INT(TODAY()>[End Date] OR [Concern (Yes/No)]="Yes")
Put that field on Columns - aggregate to either MIN or MAX, doesn't matter - and set the Mark Type as Square. Also put this field on Colour and set your colours accordingly. Put your text on the Label shelf (or Text, I forget what it's called with the Square mark type.
Option 2 - similar to what you have now. You don't need MIN(1) and MIN(0), just one of those should suffice. Make it Gantt, the above calculated field on colours and your text field on Label. This article on the Tableau placeholder technique describes how to do this.

ECharts generated label overlaps with dataZoom

Using ECharts I am giving it a data series that consists of a number of data against really values. (e.g plotting stock prices).
I also have data zoom enabled.
My issue is that the generated X axis' labels overlap with the dataZoom. I can't understand from the documentation how to fix this.
You need to set the value of grid.bottom. This will move the whole grid further from the bottom of the canvas and pull the whole X Axis with it.
Example: grid: { bottom: 60 }
// usage
this._displayedChart.setOption({ grid: { bottom: 10 } })
Not a great solution but works.
https://ecomfe.github.io/echarts-doc/public/en/option.html#grid.bottom

plotyy function showing two x-axes but only want one

I am using the plotyy function to produce the chart in the image below.
I have two issues with this chart. First issue being having two x-axes I want the zero on the left hand side of my chart to be level with the zero on the right hand side. Is there anyway I can make this happen?
Lastly I want to put some labels on the x-axis however you can that I labels have numbers on top of them. I only want the labels to be visible which I cannot seem to do?
Below is my code.
x_labels = data_cell(2:end, 1);
risk_tot = cell2mat(data_cell(2:end, 2));
risk_cont = cell2mat(data_cell(2:end, 3));
[pp,h1,h2]=plotyy((1:length(risk_tot)),risk_tot,(1:length(risk_tot)),risk_cont,'bar','stem');
set(gca,'XtickL',x_labels);
set(h1,'FaceColor',my_Blue2(40,:),'EdgeColor',my_Blue2(40,:))
set(h2,'Color',my_Orange(1,:),'LineWidth',0.5,'MarkerEdgeColor',my_Orange(1,:))
set(pp(1),'Box','off')
set(pp(2),'Box','off')
Update
I have managed to resolve the second issue with the x-axis labels. I simply added the line below. This sets the second x-axis labels to empty.
Still can't fix the first issue.
set(pp(2),'XTickLabel',[]);
Try linkaxes:
linkaxes(pp,'y')
You may need to adjust the axes limits with pp(1).Ylim = ... to get the desired result.