I was trying out the Audio Graph APIs. I'm trying to add gridlines to my chart's data axes descriptor, but doing so doesn't seem to make any difference to me. So I'm surely missing something...
I was watching the WWDC21 session "Bring accessibility to charts in your app", and the presenter says: "When you provide grid lines, they're represented in the audio graph as haptic feedback during playback and interaction." And that is quite interesting!
This is how I'm trying to do it.
var accessibilityChartDescriptor: AXChartDescriptor? {
get {
let xAxis = AXNumericDataAxisDescriptor(title: "Lines of code", range: 0...10, gridlinePositions: []) { number in
"\(number) lines"
}
let yAxis = AXNumericDataAxisDescriptor(title: "Lines of code", range: 0...40, gridlinePositions: []) { number in
"\(number) cups"
}
let dataSeriesDescriptor = AXDataSeriesDescriptor(name: "Lines of code per coffees taken", isContinuous: false, dataPoints: [20, 30, 35, 32, 28, 9, 4, 3, 15, 1].enumerated().map({ (point, index) in
AXDataPoint(x: Double(point), y: Double(index), additionalValues: [], label: nil)
}))
return AXChartDescriptor(title: "Cups of coffee vs. lines of code", summary: "This chart shows how coffee consumption impacts coding ability", xAxis: xAxis, yAxis: yAxis, additionalAxes: [], series: [dataSeriesDescriptor])
}
set {}
}
But for me, it already showed grid lines even if I didn't configure them. Once I do, they don't change visually and it is not adding any haptic feedback... So both configuring gridlines or not, the Chart Detail screen looks like this:
Any pointers on how I can achieve having gridlines that provide haptic feedback would be hugely appreciated! Many thanks!
Related
I am currently working on a specific type of chart and I am trying to achieve the following behavior for example :
As you can see there's a gap between the series last point and the xAxis max value and the reason for this is i wanna have a fix max value and load the daily values of a specific currency as the day passes by. So for example in the morning this chart would be empty and by 18:30 it would be filled.
In my mock example i have the current chart:
and when I try to set a new xAxis max value ( i also tried softMax) to a future day (using epoch converter for unixtimestamp) i am getting this:
and i set the max by doing :
return {
endOnTick: false,
max:1631962355,
tickLength: 2,
gridLineColor: '#b9b9b9',
gridLineWidth: 0,
tickColor: '#808080',
labels: {
style: {
color: '#b9b9b9',
},
x: 0,
y: 12,
format: '{value:%d.%b}',
},
visible: true,
};
}
UPDATE
After implementing your response I get an even weirder behavior. I get the same initial start I had before (no difference) but now if i click and drag it to the right I go from this :
to this:
and If i click and drag it to the left, into this:
The transformation happens without animation, neither by wathching the drag and move motion happen. It just instantly transforms after i drag my cursor pointer for a while towards the sides i mentioned above
You need to use milliseconds instead of seconds:
xAxis: {
max: 1631962355000,
...
}
Live demo: https://jsfiddle.net/BlackLabel/herncjL5/
API Reference: https://api.highcharts.com/highstock/xAxis.max
First of all, Sorry for my English. English is not my first language.
I simply want to change specific text color in Google Spreadsheets.
Example
"▶Mike: Hey, How is going on?"
In this sentence, I want to change only "▶Mike:" this part.
I have no idea what's going on in Java and programming language.
But I really need this. please help.
Thank you
If you want to change the color of a cell in Google Sheets, you can use one of the two options:
1. Use Sheets API
For updating the color of the text, you will have to use the spreadsheets.batchUpdate method.
Request
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}:batchUpdate
Body
{
"requests": [{
"repeatCell": {
"cell": {
"userEnteredFormat": {
"textFormat": {
"bold": true,
"italic": true,
"foregroundColor": {
"blue": 1.0,
"green": 0.0,
"red": 0.0
}
}
}
},
"range": {
"sheetId": 0,
"startRowIndex": 0,
"endRowIndex": 1
},
"fields": "userEnteredFormat(textFormat)"
}
}]
}
If you want to use Java, you might benefit from taking a look at this snippet from here and adapt it according to your task.
However, this option does not offer you the possibility of changing only a part of the text from the cell. For this, you should try using Apps Script.
2. Use Apps Script
Since you want to change a particular number of characters from the cell, you can use the below script
function changeColor() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getRange("A1:A2");
var redColor = SpreadsheetApp.newTextStyle()
.setForegroundColor("#ff0000")
.build();
var purpleColor = SpreadsheetApp.newTextStyle()
.setForegroundColor("#871f78")
.build();
var richTextA1 = SpreadsheetApp.newRichTextValue()
.setText("▶Mike: Hey, How is going on?")
.setTextStyle(0, 6, redColor)
.setTextStyle(7, 28, purpleColor)
.build();
var richTextA2 = SpreadsheetApp.newRichTextValue()
.setText("red words, purple words")
.setTextStyle(0, 10, redColor)
.setTextStyle(11, 23, purpleColor)
.build();
range.setRichTextValues([
[richTextA1],
[richTextA2]
]);
}
The above script creates two text styles and later applies them depending on the startOffset and the endOffset parameters which essentially represent which characters will have one of the two text styles.
After executing the above script, this is how the cells will look like:
Reference
Sheets API V4 Method: spreadsheets.batchUpdate;
Apps Script Range Class - setRichTextValues(values).
I'm using the searchkick gem in a Rails app to access Elasticsearch data. I use the aggregations feature to display a histogram on price; the relevant part of the body_options looks like this:
price: {
histogram: {
field: :low_rate,
interval: 50
}
}
The issue I'm having is that I also need to be able to provide a filter on low_rate. So, for example, if I initially have a histogram that has a range of rates between $50 and $500, and I add to the next query where low_rate < 300, the histogram buckets are recalculated and the chart is entirely redrawn. But in my app I need the chart to still show the same buckets.
This is a pretty common behavior on filters -- see the example below from Airbnb's site, which shows the chart after the upper limit being dragged down -- and so I'm hoping someone might be able to provide some advice about how to achieve this using searchkick.
I can help you with E.S Query if it helps.
{
"size": 0,
"aggs": {
"hist": {
"histogram": {
"field": "low_rate",
"interval": 50,
"extended_bounds": { // <======= It is used to extend bounds
"min": 50, // <========== Specify the min bound
"max": 500 // <========== Specify the max bound
},
"missing":10 // <========== value of the missing docs in the range
}
}
}
}
I need to know if it's possible to add some text (note/detail) on a specific point, in addition to the tooltip.
I use HighCharts Version 3.0.9.
Actually I use a click event on a points to show a popup detail in html . But i want to know if there is a native solution with HighCharts.
Like :
[
{
x: 11,
y: 11,
note: {
text: "Some text",
}
},
{
x: 16,
y: 17
}
]
Sure, it's possible. You have two options:
write your own tooltip.formatter, to get that value
use tooltip.pointFormat to create pattern for points
Second example (easier): http://jsfiddle.net/mPb4A/
tooltip: {
pointFormat: '{series.name}: <b>{point.y}: {point.options.note.text}</b><br/>'
},
Only limitation of second solution is that each point requires note property, otherwise you will get error in JS saying that Cannot read property 'text' of undefined.
I'm outputting a series of highcharts on a page. In some instances, all data for the specified time period may come back with 0 values.
In such a case, the chart looks like this: http://jsfiddle.net/charliegriefer/KM2Jx/1/
There is only 1 y-Axis label, 0, and it's in the middle of the chart.
I'd like to force that 0 value for the y-Axis to be at the bottom of the chart, which would be consistent with other charts on the page that do have data.
Have tried various yAxis properties, such as "min: 0", "minPadding: 0", "maxPadding: 0", "startOnTick: true".
Seems it should be pretty straightforward, but I'm at a loss :(
Relevant yAxis code:
yAxis: {
min: 0,
minPadding: 0,
startOnTick: true,
title: {
text: ""
}
},
I've found another (and very simple) solution:
You can set y-axis minRange property:
yAxis: {
...
minRange : 0.1
}
This makes Highcharts render yAxis min and max values when all data is 0.
UPDATE:
Highcharts 4.1.9 fix also needs:
plotOptions: {
line: {
softThreshold: false
}
}
updated js fiddle
Only way I could get it to show it "correctly" was by also providing an yAxis max value. I think this is a HighCharts issue when you provide no data elements with a y-value. It draws the best chart it thinks it can.
I had also posted this to the HighCharts forum, where I got a response that seems to work. Unfortunately, it will involve me doing some pre-processing of the data prior to rendering the charts in order to check for all "0" data values... but it'll work. Just wish there was something more "built-in" to HighCharts.
So after summing up the "y" values, if I get 0, the y-axis properties should look like this:
yAxis: {
minPadding: 0,
maxPadding: 0,
min: 0,
max:1,
showLastLabel:false,
tickInterval:1,
title: {
text: ""
}
}
See: http://jsfiddle.net/KM2Jx/2/
The keys seem to be the "max" and "showLastLabel" properties.
Here is a fix I came up with that doesn't require any preprocessing of the data and just let highcharts do it, like it used to before the update. http://jsfiddle.net/QEK3x/
if(chart.yAxis[0].dataMax === 0)
{
chart.yAxis[0].setExtremes(0, 5);
}
You only need to check the first series axis, as if the first one is not 0 then the problem won't occur. I might submit a pull request for this to high-charts, though I kinda feel like they intended for this functionality for some reason.
Since Highcharts 5.0.1, you can also use softMax.
softMax: Number
A soft maximum for the axis. If the series data maximum is greater than this, the axis will stay at this maximum, but if the series data maximum is higher, the axis will flex to show all data.
yAxis: {
min: 0,
softMax: 100,
...
}
Here is an example with a column chart : http://jsfiddle.net/84LLsepj/
Note that currently, in Highcharts 5.0.7, it doesn't seem to be working for all types of charts. As you can see in this other jsfiddle, it doesn't work with line chart.
Just add "min" option
yAxis: {
min: 0
}
For Highcharts 5.x.x, you should be able to just specify:
yAxis: {
softMin: 0,
softMax: 1,
};
This won't work for line chart, which requires that you also set minRange in the same config object as above. Experiment with different values, since defining for example minRange: 6, created a range on yAxis between 0 and 4.
minRange : 1 or whatever you feel so to be displayed in fractions of
softMax : 100 or whatever you feel so
yAxis: {
minRange : 1,
softMax: 100
}