Sometimes a chart needs to show up on both the PC and the mobile side of the scene. This requires the ability of the echarts internal components to change as the size of the container changes. To solve this problem, echarts perfected the positioning settings of the components and implemented the adaptive ability of CSS Media Query.
Positioning and layout of echarts components
Most of the components and series will follow two positioning methods:
First, left/right/top/bottom/width/height positioning method:
Of these six quantities, each quantity can be either an absolute value or a percentage or a position description.
-
Absolute value: The unit is the browser pixel (px), which is written in the number form (no units are written). For example {left: 23, height: 400} .
-
Percent: Represents the percentage of the height of the DOM container, string written in the form. For example {right: ‘30%‘, bottom: ‘40%‘} .
-
Location Description: Can be set left: ‘center‘ to indicate horizontal centering. Can be set top: ‘middle‘ to indicate vertical centering.
This six-volume concept is similar to the six-volume concept in CSS:
- Left: The distance from the right edge of the DOM container. Right: The distance from the left edge of the DOM container. Top: The distance from the top edge of the DOM container. Bottom: The distance from the lower boundary of the DOM container. Width: wide.
Height: High.
In landscape,,, and left right width Three quantities, only two can be value, because either amount determines the position and size of the component. Longitudinal,,, top bottom height Three quantities, and horizontal similarity do not repeat
二、center/ radius Positioning Method:
-
center
is an array that represents [x, y] , where, x y can be "absolute" or "percent", meaning the same as above? .
-
radius
is an array that indicates [内半径, 外半径] that the inner and outer radii can be either "absolute" or "percent", meaning the same as above.
The percent setting is useful when you are adapting the container size.
Landscape (horizontal) and portrait (vertical)
For example, on a slender mobile screen, it may be appropriate to use "Portrait Layout"; on a pc widescreen, it may be appropriate to use "landscape layout." The setting of the horizontal vertical layout, usually on the "component" or "series" orient or layout configuration item, is set to ‘horizontal‘ either ‘vertical‘ .
Media Query
Media Query provides the ability to "change as the size of the container changes"
to set Media Query in option, you must follow the following format :
Option= {Baseoption: { Here is the basic "Atom option".Title: {...},Legend: {...},Series: [{...}, {...}, ...], ... },Media: [ This defines the rule-by-point for media query. {Query: {...}, Write the rules here.Option: { Here write this rule to meet the option below.Legend: {...}, ... } }, {Query: {...}, A second rule.Option: { option that corresponds to the second rule.Legend: {...}, ... } }, { //there are no rules in this article, which means "default", Option: { //that is, when all rules are not met, this option is adopted. Legend: {...}, ... } } ]< Span class= "PLN" >};
In the example above, baseoption , and Media each option is "Atomic option", which is an option that contains individual components and series definitions.
/span>
Query
Each is query similar to this:
{ minWidth: 200, maxHeight: 300, minAspectRatio: 1.3}
Three properties are now supported: width , height , aspectRatio (aspect ratio). Each property can be added min or max prefixed. For example, minWidth: 200 means "greater than or equal to 200px width". Two attributes write together to indicate "and", for example: {minWidth: 200, maxHeight: 300} "greater than or equal to 200px width, and less than or equal to 300px height".
Option
Since the media option is "Atomic option", you can theoretically write any option configuration item. But generally we only write about layout positioning, for example, to intercept some of the above examples, query option:
Media: [ ..., {Query: {Maxaspectratio: 1 When the aspect ratio is less than 1 o'clock. },Option: {Legend: { Legend is placed in the middle of the bottom.Right: ' Center ',Bottom: 0,Orient: ' Horizontal ' Legend Horizontal layout. },Series: [ Two pie chart left and right layout. {Radius: [20, ' 50% '],Center: [ ' 50% ' , ' 30% ' ] }, {: [30 ' 50% ' ], Center: [ ' 50% ' , 70% ' ] } ]} },
{Query: {MaxWidth: 500 When the container width is less than 500. },Option: {Legend: {Right: 10, The legend is placed in the middle right.Top: ' 15% ',Orient: ' Vertical ' Portrait layout. },Series: [ Two pie chart up and down layout. {Radius: [20, ' 50% '],Center: [' 50% ', ' 30% ' ] },{ Radius: [ 30, ' 50% ' ], center< Span class= "pun" >: [ ' 50% ' ' 75% ' ] }] } }, ... ] /span>
Priority when multiple query is satisfied:
Note that there can be multiple query simultaneous gratification, which will be mergeOption defined after the merge ( i.e. higher priority ).
Default query:
If an media item is not written query , it means "default", that is, when all rules are not satisfied, this option is adopted.
Considerations when container size changes in real time:
In many cases, it is not necessary for the container DOM node to be arbitrarily sized with the drag and drop, but only a few typical sizes based on the different terminals.
However, if the container DOM node needs to be able to arbitrarily drag and drop the size, then the current use should pay attention to this matter: a configuration item, if it appears in one query option , then must appear in the other query option , or not enough to return to the original state. ( left/right/top/bottom/width/height not subject to this limitation.) )
Echars Mobile Self-adapting learning notes