Android 如何根据12小时格式,以2:00小时为间隔在x轴上绘制小时数?(同步融合颤振图)

Android 如何根据12小时格式,以2:00小时为间隔在x轴上绘制小时数?(同步融合颤振图),android,ios,flutter,dart,mobile-application,Android,Ios,Flutter,Dart,Mobile Application,我试图实现的是,我想从当前小时开始,在x轴上绘制未来12小时的小时数,间隔为2:00小时,但基于12小时格式,我在下面添加了一幅图像,以供参考。我正在使用syncfusion颤振图库 我想让我的x轴像上午8:00…上午10:00…下午12:00…下午2:00…下午4:00 所以在12:00之后,我想要2:00而不是14:00,以及上午和下午的差异 关于如何在颤振中实现这一点,有什么帮助/建议吗? 我在下面添加了代码 /// Returns the Cartesian chart with de

我试图实现的是,我想从当前小时开始,在x轴上绘制未来12小时的小时数,间隔为2:00小时,但基于12小时格式,我在下面添加了一幅图像,以供参考。我正在使用syncfusion颤振图库

我想让我的x轴像上午8:00…上午10:00…下午12:00…下午2:00…下午4:00

所以在12:00之后,我想要2:00而不是14:00,以及上午和下午的差异

关于如何在颤振中实现这一点,有什么帮助/建议吗? 我在下面添加了代码

/// Returns the Cartesian chart with default numeric x and y axis.
 SfCartesianChart getChart() {
  return SfCartesianChart(
  plotAreaBorderWidth: 0,
  legend: Legend(isVisible: true, position: LegendPosition.top),

  /// X axis as datetime axis placed here.
  primaryXAxis: DateTimeAxis(
    minimum: DateTime.now(),
    intervalType: DateTimeIntervalType.hours,
    desiredIntervals: 2,
    interval: 2,
    maximum: DateTime.now().add(
      Duration(hours: 12, minutes: 59, seconds: 59),
    ),
  ),
  primaryYAxis: NumericAxis(
      title: AxisTitle(text: 'Peak Occupancy (%)'),
      axisLine: AxisLine(width: 0),
      majorTickLines: MajorTickLines(size: 0)),
  series: getDefaultNumericSeries(),
  tooltipBehavior: TooltipBehavior(
      enable: true, format: 'Score: point.y', canShowMarker: false),
);
}

/// Returns the list of Chart series
/// which need to render on the default numeric axis.
List<ColumnSeries<ChartSampleData, DateTime>> getDefaultNumericSeries() {
int currentYear = DateTime.now().year;
int currentMonth = DateTime.now().month;
int currentDay = DateTime.now().day;
int currentHour = DateTime.now().hour;

int getHour(int hour) {
  return (DateTime.now().add(Duration(hours: hour))).hour;
}

final List<ChartSampleData> chartData = <ChartSampleData>[
  ChartSampleData(
    xValue: DateTime(currentYear, currentMonth, currentDay, currentHour),
    yValue: 240,
    secondSeriesYValue: 236,
  ),
  ChartSampleData(
      xValue: DateTime(currentYear, currentMonth, currentDay, getHour(4)),
      yValue: 250,
      secondSeriesYValue: 242),
  ChartSampleData(
      xValue: DateTime(currentYear, currentMonth, currentDay, getHour(8)),
      yValue: 281,
      secondSeriesYValue: 313),
  ChartSampleData(
      xValue: DateTime(currentYear, currentMonth, currentDay, getHour(12)),
      yValue: 358,
      secondSeriesYValue: 359),
  ChartSampleData(
      xValue: DateTime(currentYear, currentMonth, currentDay, getHour(16)),
      yValue: 237,
      secondSeriesYValue: 272)
];
return <ColumnSeries<ChartSampleData, DateTime>>[
  ///first series named "Australia".
  ColumnSeries<ChartSampleData, DateTime>(
      dataSource: chartData,
      color: const Color(0xff000000),
      //Color.fromRGBO(237, 221, 76, 1),
      name: 'Today',
      xValueMapper: (ChartSampleData sales, _) => sales.xValue,
      yValueMapper: (ChartSampleData sales, _) => sales.secondSeriesYValue),

  ///second series named "India".
  ColumnSeries<ChartSampleData, DateTime>(
      dataSource: chartData,
      color: const Color(0XFF808080).withOpacity(0.5),
      //Color.fromRGBO(2, 109, 213, 1),
      xValueMapper: (ChartSampleData sales, _) => sales.xValue,
      yValueMapper: (ChartSampleData sales, _) => sales.yValue,
      name: 'Previous Week'),
];
}
///返回带有默认数字x和y轴的笛卡尔图表。
SfCartesianChart getChart(){
返回Artesianchart(
绘图区域边界宽度:0,
图例:图例(isVisible:true,position:LegendPosition.top),
///X轴作为此处放置的日期时间轴。
primaryXAxis:DateTimeAxis(
最小值:DateTime.now(),
intervalType:DateTimeIntervalType.hours,
期望间隔:2,
间隔时间:2,
最大值:DateTime.now().add(
持续时间(小时:12,分钟:59,秒:59),
),
),
原始坐标系:数值坐标系(
标题:AxisTitle(文字:“高峰占用率(%)”),
轴线:轴线(宽度:0),
majorTickLines:majorTickLines(大小:0)),
系列:getDefaultNumericSeries(),
tooltipBehavior:tooltipBehavior(
enable:true,格式:“Score:point.y”,canShowMarker:false),
);
}
///返回图表系列的列表
///需要在默认数字轴上渲染的。
列出getDefaultNumericSeries(){
int currentYear=DateTime.now().year;
int currentmount=DateTime.now().month;
int currentDay=DateTime.now().day;
int currentHour=DateTime.now().hour;
整数小时(整数小时){
return(DateTime.now().add(Duration(hours:hour)).hour;
}
最终列表图表数据=[
图表样本数据(
xValue:DateTime(当前年、当前月、当前日、当前小时),
Y值:240,
第二系列值:236,
),
图表样本数据(
xValue:DateTime(currentYear、currentMonth、currentDay、getHour(4)),
Y值:250,
第二系列值:242),
图表样本数据(
xValue:DateTime(currentYear、currentMonth、currentDay、getHour(8)),
Y值:281,
第二系列值:313),
图表样本数据(
xValue:DateTime(currentYear、currentMonth、currentDay、getHour(12)),
Y值:358,
第二系列值:359),
图表样本数据(
xValue:DateTime(currentYear、currentMonth、currentDay、getHour(16)),
Y值:237,
第二系列值:272)
];
返回[
///第一个系列名为“澳大利亚”。
专栏系列(
数据源:chartData,
颜色:常量颜色(0xff000000),
//颜色。来自RGBO(237、221、76、1),
姓名:"今日",,
xValueMapper:(ChartSampleData sales,)=>sales.xValue,
yValueMapper:(ChartSampleData sales,)=>sales.secondSeriesYValue),
///第二个系列名为“印度”。
专栏系列(
数据源:chartData,
颜色:常量颜色(0XFF808080)。不透明度(0.5),
//颜色。来自RGBO(2,109,213,1),
xValueMapper:(ChartSampleData sales,)=>sales.xValue,
yValueMapper:(ChartSampleData sales,)=>sales.yValue,
姓名:'前一周',
];
}

正如@rickimaru指出的,您必须在构造函数中设置参数

查看文档,
DateFormat.jm()
构造函数似乎可以满足您的需要

primaryXAxis:DateTimeAxis(
最小值:DateTime.now(),
intervalType:DateTimeIntervalType.hours,
期望间隔:2,
间隔时间:2,
最大值:DateTime.now().add(
持续时间(小时:12,分钟:59,秒:59),
),
//将日期格式设置为12小时
dateFormat:dateFormat.jm(),
)
您是否尝试过在
日期时间轴中设置?