Skip to content

Set string on y-axis #815

@AFazakas-UAH

Description

@AFazakas-UAH

Hi!, I am developing an app in which I want to show a line graph. In this graph I want to show in which room an individual has been in at any given moment. To do this we have a list called roomList with the following structure:

class RoomData {
  String room;
  DateTime timestamp;
  int CodHabitacionSensor;

  RoomData(this.room, this.timestamp, this.CodHabitacionSensor);
}

As shown this list contains three variables, room is a string that for example is bathroom whose CodHabitacionSensor corresponds to 3, what I have achieved so far is to show the graph with the integers, however I am not able to put on the Y axis the string bathroom, and I can only represent the integer CodHabitacionSensor . Next I show you the implemented code

child: SfCartesianChart(
  plotAreaBorderWidth: 0,
  primaryXAxis: DateTimeAxis(
      dateFormat: DateFormat('HH:mm d/M/y'),
      majorGridLines: const MajorGridLines(width: 0)),
  primaryYAxis: NumericAxis(
      axisLine: const AxisLine(width: 0),
      labelFormat: '{value} ',
      majorTickLines: const MajorTickLines(size: 0)),
  series: _getRoomLineSeries(),
  trackballBehavior: _trackballBehavior,
),
List<LineSeries<RoomData, DateTime>> _getRoomLineSeries() {
  return <LineSeries<RoomData, DateTime>>[
    LineSeries<RoomData, DateTime>(
        animationDuration: 2500,
        dataSource: roomList!,
        xValueMapper: (RoomData sales, _) => sales.timestamp,
        yValueMapper: (RoomData sales, _) => sales.CodHabitacionSensor,
        width: 2,
        markerSettings: const MarkerSettings(isVisible: true)),
  ];
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions