F2Chart

4 min read

The graphics instruction generation engine uses graphics syntax theory to encapsulate the api, and finally generates drawing instructions to the drawing engine for drawing.

Create F2Chart instance

iOS

// define
/// Quickly create chart
/// @param size dp is the unit
/// @param name The name will be appended when outputting the log
+ (F2Chart *)chart:(CGSize)size name:(NSString *)name;

// demo
#import <F2/F2.h>
F2Chart *chart = [F2Chart chart:f2Canvas.view.bounds.size name:@"F2chart"];

Android

F2Chart chart = F2Chart.create(context, "ChartName", width, height);
  • parameters
Attribute NameTypeExplanation
size, width, heightSizeThe size of the canvas to draw the graphics
nameStringCustom graphic name, mainly used for log output

Method

- canvas

Set the drawing engine instance corresponding to the current graphics command engine

iOS

  chart.canvas(f2CanvasView);

Android

  chart.setCanvas(canvasView);

- padding

set padding [left, top, right, bottom]

iOS

  chart.padding(10, 0.f, 0.f, 0.f).;

Android

  chart.padding(10, 0.f, 0.f, 0.f).;

- margin

Set graphics margin [left, top, right, bottom]

iOS

  chart.margin(10, 0.f, 0.f, 0.f);

Android

  chart.margin(10, 0.f, 0.f, 0.f);

### - source set data source #### iOS ````obj-c NSString *jsonString = @"[{\"date\":\"2010-01-10\",\"value\":99.9}{\"date\":\"2010-02-10\",\ "value\":96.7},{\"date\":\"2010-03-10\",\"value\":100.2}]" chart.source(jsonString); ````

Android

  chart.source(jsonString);
  • parameters
Attribute NameTypeExplanation
jsonStringDrawing data jsonString, must be of type jsonArray

- scale

set metric

iOS

  chart.scale(@"date", @{@"type":@"identity", @"scaleRange": @[@(0.1), @(0.9)] });
  chart.scale(@"value", @{ @"precision": @(1), @"max": @(200), @"min": @(0)});

Android

  chart.setScale("value", new F2Chart.ScaleConfigBuilder().max(100).min(20));
  chart.setScale("date", new F2Chart.ScaleConfigBuilder().tickCount(5));
  • parameters
Attribute NameTypeExplanation
fieldStringThe name of the data currently to be measured in source
configDictionaryThe specific configuration information of the measurement see here

- Coord

set coordinate system

iOS

    chart.coord(@{@"type": @"polar", @"transposed": @(YES)});

Android

// TODO
  • parameters Type: Dictionary
Attribute NameTypeExplanation
typeStringpolar - polar coordinates
rect - plane rectangular coordinates
transposedBOOLwhether to flip

- Axis

Set the coordinate axis configuration; the coordinate axis of F2-Native is composed as follows

iOS

 chart.axis(@"date", @{ @"grid": @(NO) });
 chart.axis(@"value", @{
              @"line": @(NO),
              @"grid": @{
                @"type": @"dash",
                @"lineWidth": @(1.0f),
                @"stroke": @"#E6E6E6",
                @"lineDash": @[@(6),@(3)]
             },
              @"label": @{ @"textColor": @"#cccccc" ,@"textAlign":@"end",@"labelOffset":@(5)}
        });

Android

chart.setAxis("year", new F2Chart.AxisConfigBuilder()
        .label(new F2Chart.AxisLabelConfigBuilder().labelOffset(5.f))
        .gridHidden());
chart.setAxis("sales", new F2Chart.AxisConfigBuilder()
        .label(new F2Chart.AxisLabelConfigBuilder().labelOffset(5))
        .grid(new F2Chart.AxisGridConfigBuilder().type("dash"))
        .line(new F2Chart.AxisLineConfigBuilder().lineWidth(1).color("#E6E6E6").type("dash").lineDash(new double[]{6, 3})));
  • parameters
Attribute NameTypeExplanation
fieldStringThe name of the data represented by the current axis in source
configDictionaryThe specific configuration information of the coordinate axis see here for details

- Line

Create a line instance; F2Line configuration information see here

- Interval

Create a column instance; F2Interval configuration information see here

- Area

Create a shadow instance; F2Area configuration information see here

- Guide

Create an auxiliary instance; the configuration information of F2Guide see here for details


- OnTouchEvent

Send interactive gesture information

iOS

 - (void)handleGestureInfo:(NSDictionary *)info {
    // do something
    chart.OnTouchEvent(info);
}

Android

// TODO
  • return data format
Attribute NameTypeExplanation
infoDictionaryIf there is no special need, the info information of the callback can be returned directly

- legend

legend(filed,config); // set legend

iOS

   chart.legend(@"type", @{@"radius": @(3), @"symbol": @"square"});
}

Android

// TODO
  • return data format
Attribute NameTypeExplanation
filedStringReturns the name of the corresponding field to display the legend
configDictionaryConfiguration information see here

- render

render operation

iOS

  // ...
  // After the chart configuration and graphic elements are created, start rendering
  chart.render();

Android

  // ...
  // The chart configuration and graphic elements are created, start rendering
  chart.render();