Skip to content

SfCartesianChart (Multiple LineSeries display errors) #19

Closed

Description

@DingProg
  • flutter version any
  • syncfusion_flutter_charts : ^18.3.40 or other version

The display error is as follows

image

Code

import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_charts/charts.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: TargetCacheRateChart(),
    );
  }
}

class TargetCacheRateChart extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    List<TestEntity> list = [
      TestEntity("10-01", 25.4),
      TestEntity("10-02", 26.4),
      TestEntity("10-03", 26.8),
      // TestEntity("10-04", 25.6),
      // TestEntity("10-05", 24.3),
      // TestEntity("10-06", 25.6),
      // TestEntity("10-07", 25.8),
      TestEntity("10-08", 24.6),
      TestEntity("10-09", 25.6),
      TestEntity("10-10", 26.6),
      TestEntity("10-11", 26.4),
      TestEntity("10-12", 26.7),
      TestEntity("10-13", 26.3),
      TestEntity("10-14", 26.7),
    ];

    List<TestEntity> list2 = [
      TestEntity("10-01", 35.4),
      TestEntity("10-02", 36.4),
      TestEntity("10-03", 36.8),
      TestEntity("10-04", 35.6),
      TestEntity("10-05", 14.3),
      TestEntity("10-06", 35.6),
      TestEntity("10-07", 45.8),
      TestEntity("10-08", 34.6),
      TestEntity("10-09", 35.6),
      TestEntity("10-10", 36.6),
      // TestEntity("10-11", 26.4),
      // TestEntity("10-12", 26.7),
      // TestEntity("10-13", 26.3),
      // TestEntity("10-14", 26.7),
    ];

    List<LineSeries> buildCacheRate = [
      LineSeries<TestEntity, String>(
          name: "line1",
          dataSource: list,
          xValueMapper: (TestEntity entity, _) => entity.date,
          yValueMapper: (TestEntity entity, _) => entity.y),
      LineSeries<TestEntity, String>(
          name: "line2",
          dataSource: list2,
          xValueMapper: (TestEntity entity, _) => entity.date,
          yValueMapper: (TestEntity entity, _) => entity.y),
    ];

    return Container(
        child: SfCartesianChart(
            plotAreaBorderWidth: 0,
            primaryXAxis: CategoryAxis(
              majorGridLines: MajorGridLines(width: 0),
              axisLine: AxisLine(width: 0),
            ),
            palette: [
              new Color(0xFF5B8FF9),
              new Color(0xFFE8684A),
            ],
            primaryYAxis: NumericAxis(
                axisLine: AxisLine(width: 0),
                labelFormat: '{value} %',
                majorTickLines: MajorTickLines(size: 0)),
            legend: new Legend(isVisible: true),
            series: buildCacheRate));
  }
}

class TestEntity {
  String date;
  double y;

  TestEntity(this.date, this.y);
}

Activity

  1. SriramKiranSenthilkumar commented on Oct 16, 2020

    @SriramKiranSenthilkumar
    Contributor

    HI @DingProg ,

    Greetings from Syncfusion. We have analyzed your scenario and we would like to share some information regarding the rendering behaviour of the chart with category series values. If there are two series available in the chart with the different category data source values, then the arrangeByindex property of the CategoryAxis should be set to _true_ which will group the series data points according to their index and if the two series have similar category data source values, then there is no need to set this property. As your two series data source in your chart has different category x-values, kindly set the arrangeByIndex property value as _true_ so that the series gets rendered properly in the chart. We have also tested this with the provided code snippet.
    code snippet:

    SfCartesianChart(
              primaryXAxis: CategoryAxis(
                 // Axis will be rendered based on the index values
                 arrangeByIndex: true
              ),
    )
    

    Screenshtot:
    Screenshot

    For further reference on arrangeByIndex property, please check the user guide below.
    https://help.syncfusion.com/flutter/cartesian-charts/axis-types#indexed-category-axis

    Please get in touch with us if you require further assistance.

    Regards,
    Sriram Kiran

  2. DingProg commented on Oct 19, 2020

    @DingProg
    Author

    Thank you very much

    This is ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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