Skip to content

Commit

Permalink
update: add radar chart sample
Browse files Browse the repository at this point in the history
  • Loading branch information
Koooooo-7 committed Jul 2, 2024
1 parent 8c13857 commit 3082d48
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import com.github.koooooo7.echarts4j.option.series.BarChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.ListChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.LineChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.SeriesOption;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -97,7 +97,7 @@ void shouldServerChart_WhenUseTheChartServer_GivenChartAndCallTheRender() throws
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName)
.data(data1)
.build())
Expand Down Expand Up @@ -137,7 +137,7 @@ void shouldServerLiveUpdateChart_WhenUseTheChartServer_GivenChartWithCustomUpdat
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName)
.data(data1)
.build())
Expand Down Expand Up @@ -207,7 +207,7 @@ void shouldServerLiveUpdateChart_WhenUseTheChartServer_Given2ChartWithDifferentU
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName)
.data(data1)
.build())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package com.github.koooooo7.echarts4j.chart;

import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

import java.util.Objects;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class BarChart extends BaseChart<BarChart> {
@Builder.Default
private ChartType chartType = ChartType.Bar;

@Override
public void postProcessor() {
super.postProcessor();
if (Objects.isNull(getChartOptions().getXAxis())) {
getChartOptions().setXAxis(XAxis.builder().build());
}
if (Objects.isNull(getChartOptions().getYAxis())) {
getChartOptions().setYAxis(YAxis.builder().build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public enum ChartType {
Bar("bar"),
Pie("pie"),
Scatter("scatter"),
EffectScatter("effectScatter")

;
EffectScatter("effectScatter"),
Radar("radar");
private final String type;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
package com.github.koooooo7.echarts4j.chart;

import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

import java.util.Objects;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class LineChart extends BaseChart<LineChart> {
@Builder.Default
private ChartType chartType = ChartType.Line;

@Override
public void postProcessor() {
super.postProcessor();
if (Objects.isNull(getChartOptions().getXAxis())) {
getChartOptions().setXAxis(XAxis.builder().build());
}
if (Objects.isNull(getChartOptions().getYAxis())) {
getChartOptions().setYAxis(YAxis.builder().build());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.koooooo7.echarts4j.chart;

import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

@Data
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
public class RadarChart extends BaseChart<RadarChart> {
@Builder.Default
private ChartType chartType = ChartType.Radar;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.koooooo7.echarts4j.option.chart.Grid;
import com.github.koooooo7.echarts4j.option.chart.Legend;
import com.github.koooooo7.echarts4j.option.chart.Radar;
import com.github.koooooo7.echarts4j.option.chart.Toolbox;
import com.github.koooooo7.echarts4j.option.chart.Tooltip;
import com.github.koooooo7.echarts4j.option.chart.XAxis;
Expand All @@ -29,6 +30,7 @@ public class ChartOption {
private XAxis xAxis;
@JsonProperty("yAxis")
private YAxis yAxis;
private Radar radar;
private Tooltip tooltip;
private Toolbox toolbox;
private Object color;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.koooooo7.echarts4j.option.chart;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.github.koooooo7.echarts4j.type.FuncStr;
import lombok.Builder;
import lombok.Data;

import java.util.List;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Radar {
private String id;
@JsonProperty("zlevel")
private Integer zLevel;
private Integer z;
private FuncStr center;
private Object radius;
private List<IndicatorDataItem> indicator;


@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class IndicatorDataItem {
private String name;
private Integer max;
private Integer min;
private String color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
@EqualsAndHashCode(callSuper = true)
public class ListChartSeriesOption extends GenericSeriesOption implements SeriesOption {
public class LineChartSeriesOption extends GenericSeriesOption implements SeriesOption {
@Builder.Default
private String type = ChartType.Line.getType();
private List<?> data;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.koooooo7.echarts4j.option.series;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.github.koooooo7.echarts4j.chart.ChartType;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.SuperBuilder;

import java.util.List;

@Data
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
@EqualsAndHashCode(callSuper = true)
public class RadarChartSeriesOption extends GenericSeriesOption implements SeriesOption {
@Builder.Default
private String type = ChartType.Radar.getType();
private List<?> data;


@Data
@SuperBuilder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class RadarDataItem {
private String name;
private Integer value;
private String groupId;
private String childGroupId;
private String symbol;
private Object symbolSize;
private Integer symbolRotate;
private Boolean symbolKeepAspect;
private List<?> symbolOffset;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.github.koooooo7.echarts4j.option.chart.Toolbox;
import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import com.github.koooooo7.echarts4j.option.series.ListChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.LineChartSeriesOption;
import com.github.koooooo7.echarts4j.render.Render;
import com.github.koooooo7.echarts4j.render.RenderProvider;
import com.github.koooooo7.echarts4j.type.FuncStr;
Expand Down Expand Up @@ -66,11 +66,11 @@ void shouldRenderCorrectly_WhenRenderTheLineCharts_GivenRelatedConfigs() throws
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName)
.data(data1)
.build())
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName2)
.data(data2)
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import com.github.koooooo7.echarts4j.option.series.BarChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.ListChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.LineChartSeriesOption;
import com.github.koooooo7.echarts4j.render.Render;
import com.github.koooooo7.echarts4j.render.RenderProvider;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.FileWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -54,7 +53,7 @@ void showRenderOverlapChart_WhenCallTheOverlapViaSeries_GivenCorrectConfigs() {
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName)
.data(data1)
.build())
Expand Down Expand Up @@ -108,7 +107,7 @@ void showRenderOverlapChart_WhenCallTheOverlapViaChartOverlapMethod_GivenCorrect
.build())
.yAxis(YAxis.builder().build())
.build()
.addSeries(ListChartSeriesOption.builder()
.addSeries(LineChartSeriesOption.builder()
.name(seriesName2)
.data(data1)
.build())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.github.koooooo7.echarts4j.chart;

import com.github.koooooo7.echarts4j.helper.DataHelper;
import com.github.koooooo7.echarts4j.option.ChartOption;
import com.github.koooooo7.echarts4j.option.chart.Legend;
import com.github.koooooo7.echarts4j.option.chart.Radar;
import com.github.koooooo7.echarts4j.option.chart.Title;
import com.github.koooooo7.echarts4j.option.series.RadarChartSeriesOption;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

public class RadarChartTests {
@Test
void shouldGenerateScatterChart_WhenCallThePieChartConfig_GivenNecessaryConfigs() {
List<Integer> item = new ArrayList<>();
List<Integer> item2 = new ArrayList<>();
for (int i = 0; i < 20; i++) {
item.add(ThreadLocalRandom.current().nextInt(5000, 16000));
item2.add(ThreadLocalRandom.current().nextInt(5000, 16000));
}

final List<LinkedHashMap<String, Object>> finalData = DataHelper.create()
.addNameField()
.addValueField(List.class)
.build()
.addData("Promotion", item)
.addData("Baseline", item2)
.get();
final List<String> legendDate = new ArrayList<>();
legendDate.add("Allocated Budget");
legendDate.add("Actual Spending");

final List<Radar.IndicatorDataItem> indicator = new ArrayList<>();
indicator.add(Radar.IndicatorDataItem.builder().name("Sales").max(16500).build());
indicator.add(Radar.IndicatorDataItem.builder().name("Administration").max(26000).build());
indicator.add(Radar.IndicatorDataItem.builder().name("Information Technology").max(35000).build());
indicator.add(Radar.IndicatorDataItem.builder().name("Customer Support").max(16500).build());
indicator.add(Radar.IndicatorDataItem.builder().name("Development").max(65000).build());
indicator.add(Radar.IndicatorDataItem.builder().name("Marketing").max(16500).build());

Canvas.builder()
.addCharts(RadarChart.builder()
.options(ChartOption.builder()
.title(Title.builder().text("Basic Radar Chart").build())
.legend(Legend.builder().data(legendDate).build())
.radar(Radar.builder()
.indicator(indicator)
.build())
.build()
.addSeries(RadarChartSeriesOption.builder()
.name("P&L")
.data(finalData)
.build()))
.build())
.build()
.render();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.github.koooooo7.echarts4j.option.chart.XAxis;
import com.github.koooooo7.echarts4j.option.chart.YAxis;
import com.github.koooooo7.echarts4j.option.series.EffectScatterChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.ListChartSeriesOption;
import com.github.koooooo7.echarts4j.option.series.ScatterChartSeriesOption;
import com.github.koooooo7.echarts4j.render.Render;
import com.github.koooooo7.echarts4j.render.RenderProvider;
Expand All @@ -17,7 +16,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
Expand Down

This file was deleted.

Loading

0 comments on commit 3082d48

Please sign in to comment.