Skip to content

Commit

Permalink
feat:新增chartBackgroundColor、lineWidth、fillFormatter属性 (#23)
Browse files Browse the repository at this point in the history
Co-authored-by: hongtenglong <[email protected]>
  • Loading branch information
tenglonghh and hongtenglong authored Sep 6, 2024
1 parent 71e83b7 commit 8a82a30
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 22 deletions.
5 changes: 4 additions & 1 deletion harmony/charts-wrapper/src/main/ets/BarLineBaseChart.ets
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ export const setBarLineChart = <T extends model, U extends RNChart>(descriptorWr
if (props.gridBackgroundColor != undefined) {
model.setGridBackgroundColor(props.gridBackgroundColor)
}

//设置图表背景 chartBackgroundColor
if(props.chartBackgroundColor!=undefined){
model.setGridBackgroundColor(props.chartBackgroundColor)
}
//是否设置边框 drawBorders
if (props.drawBorders != undefined) {
model.setDrawBorders(props.drawBorders);
Expand Down
23 changes: 11 additions & 12 deletions harmony/charts-wrapper/src/main/ets/BaseCharts.ets
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import {
HorizontalBarChartModel,
LegendEntry,
JArrayList,
IAxisValueFormatter,
AxisBase,
} from '@ohos/mpchart';
import { RNC } from "@rnoh/react-native-openharmony/generated"
import { setAxis } from './AxisBase';
Expand Down Expand Up @@ -254,9 +256,6 @@ export const setBaseProps =
model.setLogEnabled(props.logEnabled)
}


//chartBackgroundColor 暂无这个方法

//设置高亮 highlightPerTapEnabled
if (props.highlightPerTapEnabled != undefined) {
model.setHighlightPerTapEnabled(props.highlightPerTapEnabled);
Expand Down Expand Up @@ -327,14 +326,14 @@ export const setBaseProps =
xAxis?.setYOffset(props.xAxis.yOffset)
}

if (props.highlights) {
props.highlights.forEach((highlight) => {
let x = highlight.x;
let dataSetIndex = highlight.dataSetIndex;
let stackIndex = highlight.stackIndex;
model.highlightValue(x, dataSetIndex, stackIndex)
})
}
}

if (props.highlights != undefined) {
props.highlights.forEach((highlight) => {
let x = highlight.x;
let dataSetIndex = highlight.dataSetIndex;
let stackIndex = highlight.stackIndex;
model.highlightValue(x, dataSetIndex, stackIndex)
})
}
}

29 changes: 28 additions & 1 deletion harmony/charts-wrapper/src/main/ets/Data/LineData.ets
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
LineData,
LineDataSet,
Mode,
CombinedData
CombinedData,
ChartColorStop
} from '@ohos/mpchart';
import { RNC } from '@rnoh/react-native-openharmony/generated';

Expand Down Expand Up @@ -178,6 +179,19 @@ export const setLineData = (isLine: string, descriptorWrapper: RNC.RNLineChart.D
dataSet.setDrawHighlightIndicators(config?.drawHighlightIndicators)
}

// 设置折线宽度,以vp为单位 lineWidth
if (config?.lineWidth != undefined) {
dataSet.setLineWidth(config.lineWidth);
}

//设置填充 fillFormatter
if(config?.drawFilled && config.fillColor!=undefined){
let gradientFillColor = new JArrayList<ChartColorStop>();
let fillColor = config.fillColor.toString();
gradientFillColor.add([fillColor,config.fillAlpha]);
dataSet.setGradientFillColor(gradientFillColor);
dataSet.setDrawFilled(config.drawFilled)
}

dataSetList.add(dataSet);
})
Expand Down Expand Up @@ -316,6 +330,19 @@ export const setLineData = (isLine: string, descriptorWrapper: RNC.RNLineChart.D
if (config?.drawHighlightIndicators != undefined) {
dataSet.setDrawHighlightIndicators(config?.drawHighlightIndicators)
}
// 设置折线宽度,以vp为单位 lineWidth
if (config?.lineWidth != undefined) {
dataSet.setLineWidth(config.lineWidth);
}

//设置填充 fillFormatter
if(config?.drawFilled && config.fillColor!=undefined){
let gradientFillColor = new JArrayList<ChartColorStop>();
let fillColor = config.fillColor.toString();
gradientFillColor.add([fillColor,config.fillAlpha]);
dataSet.setGradientFillColor(gradientFillColor);
dataSet.setDrawFilled(config.drawFilled)
}



Expand Down
10 changes: 2 additions & 8 deletions harmony/charts-wrapper/src/main/ets/RadarCharts.ets
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
IAxisValueFormatter,
AxisBase,
ChartColor,
XAxis,
XAxisPosition,
} from '@ohos/mpchart';
import { RNC } from "@rnoh/react-native-openharmony/generated"
import { setBaseProps } from './BaseCharts'
Expand All @@ -39,14 +41,6 @@ import { setBasePieChartProps } from './BasePieCharts';
import { setAxis } from './AxisBase';
import RadarMarkerView from './utils/RadarMarkerView';

class valueFormatter implements IAxisValueFormatter {
private mActivities: string[] = ["Burger", "Steak", "Salad", "Pasta", "Pizza"];

getFormattedValue(value: number, axis: AxisBase): string {
return this.mActivities[Math.floor(value % this.mActivities.length)];
}
}

@Component
export struct RadarCharts {
public static readonly NAME = RNC.RNRadarChart.NAME;
Expand Down

0 comments on commit 8a82a30

Please sign in to comment.