aligning zero line in echarts - javascript

normally I would have some full-blwn code to post with my questions but this is a very generic question... I have create a chart with two y-axis on echarts through yAxis: [{name:'abc', type:'value'},{name:'xyz',type:'value'}]. both axes might have data that goes to negative, but the second axis doesn't always have negative numbers. I would like both axes' 0 value line to align at the same level at all times. As the range of both axes individually might vary greatly depending on the dataset supplied, I wouldn't want to manually set the ranges for them and would like to rely on echarts built-in capability to decide on an appropriate range as long as the zero line is aligned. is this possible at all? thanks in advance

Related

Prevent Recharts Tick Marks from Overlapping

I am developing an application which allows a user to select dynamically queried data which can then be used in Recharts visualizations. There are certain edge cases where the default formatting / rendering within recharts produces an ugly result. For example, if there are many unique values passed to the <XAxis /> component then the chart produced will likely have overlapping text for the ticks.
There does not seem to be any good "render as many ticks as possible, without overlapping" option described in the documentation. These appear to be the only options:
Render all ticks (obviously leads to too many ticks)
<XAxis
dataKey={xAxisField.name}
name={getXAxisLabel(xAxisField, chartType)}
tickFormatter={
getMetaDataType(xAxisField) ===
"DATE"
? tickEpochFormatter // force numbers to be displayed as 'YYYY-MM-DD'
: tickNumberFormatter
}
allowDataOverflow={false}
ticks={xValues.sort()} // gets all of the values
interval={0} // display all of values, instead of the default 5
angle={-90} // force text to be 90, reading towards the graph
textAnchor="end" // rather than setting "dy={50}" or something
>
Render only the start / end / start & end, which depends (seemingly) entirely on the width of the text, prior to rotation.
<XAxis
dataKey={xAxisField.name}
name={getXAxisLabel(xAxisField, chartType)}
tickFormatter={
getMetaDataType(xAxisField) ===
"DATE"
? tickEpochFormatter // force numbers to be displayed as 'YYYY-MM-DD'
: tickNumberFormatter
}
allowDataOverflow={false}
ticks={xValues.sort()} // gets all of the values
interval="preserveStart" // ensure that everything can be read, giving preference to the "left"???
angle={-90} // force text to be 90, reading towards the graph
textAnchor="end" // rather than setting "dy={50}" or something
>
Hardcode the number of intervals to ensure a maximum? I'm not sure if this is a viable option since I would need to know how many ticks are truly overlapping. Just seems like a crude approach.
Is it even possible to have Recharts render as many things as possible, even if they are rotated 90 degrees, and then selectively choose what has enough space to display? Is it possible to have the angle property dynamically update based on the length of the tick mark texts?
Here is a list of links, none of which seems to answer these questions:
Recharts Docs
Recharts XAxis Docs
Recharts LineChartAxisInterval Docs
Github Recharts repo
Show all ticks
Vertical Axis Label
Rotated Axis Labels
Rotate tick text
Axis Labels Display Over Data
Axis Labels Look Awful
Last XAxis label not aligned with tick mark when rotated -45 degrees
Prevent hiding of tick labels
Missing ticks on x-axis
Long strings in labels generate overlap in YAxis for horizontal barchart
StackOverflow Posts
Scalable YAxis Label
Display all XAxis ticks
YAxis Ticks don't auto calculate
Set Label Margin
Here's a picture of the problematic rendering I want to clean up:
Also, please note that normally I would prefer to stick to the same library that I have been using, but if another library is better suited for this use-case, I would like to consider switching!
I had the same problem, ended up removing the interval property which set the ticks to be sort-of-dynamic but had only 4 or 5 ticks.
So I set the minTickGap to some negative value. the result was that more ticks appeared on the axis
<XAxis dataKey="date"
angle={45}
dx={15}
dy={20}
minTickGap={-200}
axisLine={false}/>
before
after:

Highchart: How to calculate the distance between each bar in Bar chart

I need to show all the text in label without ellipsis, But I cannot predict the number of lines that the label will take.
Is it possible to give some margin between each label and show
the bar in center align to label? (with or without varying the
distance between each bar)
Is it possible to calculate the distance between each bar?
Is it possible to calculate the number of lines the label will take?
Here I am setting the height of the chart with number of bars in it with a random guess of each label taking 4 lines.
Image is altered, Sometimes it there are labels with single lines & some times multiple lines.
Example:
This information may be useful in context of the question 3. (answers for questions 1 & 2 appeared in the comments below the question):
Dividing a label text to separate lines (in case when useHTML === false) is performed in Highcharts.SVGRenderer.prototype.buildText function.
In this live demo I've overwritten this core function and added console.log that prints how many <tspans> were generated for a specific line: http://jsfiddle.net/kkulig/x2619jmv/
It seems that Highcharts may run it multiple times before it finds the proper configuration of the labels.

Area/Line chart not working as expected with stacking : percent and negative values

I'm trying to make a population pyramid type of chart with both bars and lines at the same time.
I also need to place a checkbox to allow the user to switch to percent values.
The problem i'm facing is that the line series are not behaving the same as the bar series when i set stacking:percent
The values of the two line series are copied with just a minus in front so i'd expect to see all the values to 50% when switching to percent. But for some reason the blue line is always at 0%.
jsFiddle
EDIT:
As Bobby Orndorff explained in the comment:
When stacking line/area series, you add the values of the second series to the values of the first series. If the values of the second series have the same magnitude but different sign then the sum will be zero (i.e. the second series will be plotted at zero). When stacking bar series, positive values are stacked above the zero and negative values are stacked below zero.
So now my question is:
How do i achieve the same effect as the bar series but using the line/area series? Is it possible without manually editing the dataseries (doing the percentages myself)?

Make X axis labels show each day in Gantt chart

I have a Gantt chart, and I need to make the duration scale to one day. Currently there's a label for every other day only.
See image below:
The axis chooses granularity and number of labels / grid lines based on available space, so that it does not look crammed.
You can influence it in a number of ways:
1) Set (reduce) minHorizontalGap for your value axis.
This setting defines how much free space there should be between labels. The less the number the more labels the chart will display.
OR
2) Disable autoGridCount and set gridCount manually.
With both approaches you might need to play around with the numbers to find the one that works for your chart setup and available space.

highchart - scatter : set decimals of x-axis and y-axis

Part I
I want to fix decimals of the x-axis and y-axis elements in the scatter-plot (highcharts).
I've searched documentation in highcharts about properties of scatter-plot. But, I've found nothing. I want to set 2 decimals of elements in x-axis and y-axis because I have a very large number with 8 decimals o more.
Part II
Well, It works the decimals. However, the element of x-axis and y-axis have the same value now. Is it possible to fix this?. I would like the difference between each element of axis equals 0.1. I mean 34.66, 34.67, 34.68, 34.69
Part II -This is the new problem now
Part I - You can see the picture. This is the problem
Use a formatter function with .toFixed(2). Example jsFiddle.

Categories

Resources