Dynamically set color of line/spline in Nativescript-UI-Chart?












1















I need to match the color of each line in a chart to the color given by the object providing the data. The meter.color variable holds the color I need to use.






<StackLayout class="container" orientation="vertical">
<Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
<RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
<ng-container *ngFor="let meter of readings$ | async">
<ng-container [ngSwitch]="meter.type">

<LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
[items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
<Palette tkCartesianPalette seriesName="Line">
<PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
</Palette>
</LineSeries>

<SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
[items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
<Palette tkCartesianPalette seriesName="Spline">
<PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
</Palette>
</SplineSeries>

</ng-container>
<RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
<RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
<LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
<DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
</ng-container>
</RadCartesianChart>
</StackLayout>





At the moment the line gets one color and the spline get another. But if i have more than two lines or splines all lines get the same color and all splines also get the same color. It seems that the last line added sets the color of both lines, the same goes for the spline.










share|improve this question



























    1















    I need to match the color of each line in a chart to the color given by the object providing the data. The meter.color variable holds the color I need to use.






    <StackLayout class="container" orientation="vertical">
    <Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
    <RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
    <ng-container *ngFor="let meter of readings$ | async">
    <ng-container [ngSwitch]="meter.type">

    <LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
    [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
    <Palette tkCartesianPalette seriesName="Line">
    <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
    </Palette>
    </LineSeries>

    <SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
    [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
    <Palette tkCartesianPalette seriesName="Spline">
    <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
    </Palette>
    </SplineSeries>

    </ng-container>
    <RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
    <RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
    <LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
    <DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
    majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
    </ng-container>
    </RadCartesianChart>
    </StackLayout>





    At the moment the line gets one color and the spline get another. But if i have more than two lines or splines all lines get the same color and all splines also get the same color. It seems that the last line added sets the color of both lines, the same goes for the spline.










    share|improve this question

























      1












      1








      1








      I need to match the color of each line in a chart to the color given by the object providing the data. The meter.color variable holds the color I need to use.






      <StackLayout class="container" orientation="vertical">
      <Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
      <RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
      <ng-container *ngFor="let meter of readings$ | async">
      <ng-container [ngSwitch]="meter.type">

      <LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Line">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </LineSeries>

      <SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Spline">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </SplineSeries>

      </ng-container>
      <RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
      <RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
      <LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
      <DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
      majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
      </ng-container>
      </RadCartesianChart>
      </StackLayout>





      At the moment the line gets one color and the spline get another. But if i have more than two lines or splines all lines get the same color and all splines also get the same color. It seems that the last line added sets the color of both lines, the same goes for the spline.










      share|improve this question














      I need to match the color of each line in a chart to the color given by the object providing the data. The meter.color variable holds the color I need to use.






      <StackLayout class="container" orientation="vertical">
      <Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
      <RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
      <ng-container *ngFor="let meter of readings$ | async">
      <ng-container [ngSwitch]="meter.type">

      <LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Line">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </LineSeries>

      <SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Spline">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </SplineSeries>

      </ng-container>
      <RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
      <RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
      <LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
      <DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
      majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
      </ng-container>
      </RadCartesianChart>
      </StackLayout>





      At the moment the line gets one color and the spline get another. But if i have more than two lines or splines all lines get the same color and all splines also get the same color. It seems that the last line added sets the color of both lines, the same goes for the spline.






      <StackLayout class="container" orientation="vertical">
      <Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
      <RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
      <ng-container *ngFor="let meter of readings$ | async">
      <ng-container [ngSwitch]="meter.type">

      <LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Line">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </LineSeries>

      <SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Spline">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </SplineSeries>

      </ng-container>
      <RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
      <RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
      <LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
      <DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
      majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
      </ng-container>
      </RadCartesianChart>
      </StackLayout>





      <StackLayout class="container" orientation="vertical">
      <Label class="title" [text]="widget.settings.title" horizontalAlignment="center"></Label>
      <RadCartesianChart class="chart" tkExampleTitle tkToggleNavButton>
      <ng-container *ngFor="let meter of readings$ | async">
      <ng-container [ngSwitch]="meter.type">

      <LineSeries tkCartesianSeries seriesName="Line" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + meter.unit"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Line">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </LineSeries>

      <SplineSeries tkCartesianSeries seriesName="Spline" *ngSwitchCase="'spline'" [legendTitle]="meter.name"
      [items]="meter.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
      <Palette tkCartesianPalette seriesName="Spline">
      <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
      </Palette>
      </SplineSeries>

      </ng-container>
      <RadLegendView tkCartesianLegend position="Top" title="Series" enableSelection="true"></RadLegendView>
      <RadCartesianChartGrid tkCartesianGrid horizontalLinesVisible="true" verticalStrokeColor="#804d0026"></RadCartesianChartGrid>
      <LinearAxis tkCartesianVerticalAxis horizontalLocation="Left" android:labelFormat="%.0f"></LinearAxis>
      <DateTimeContinuousAxis tkCartesianHorizontalAxis dateFormat="hh:mm" [minimum]="backwardHour" [maximum]="forwardHour"
      majorStep="Hour" labelFitMode="Rotate"></DateTimeContinuousAxis>
      </ng-container>
      </RadCartesianChart>
      </StackLayout>






      angular2-nativescript nativescript-telerik-ui






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 8:50









      Johannes KraftJohannes Kraft

      479




      479
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I found a solution to my problem, i added property binding to seriesName on both the LineSeries and to the PaletteEntry witch matches each line dynamically to a ID.



          Changes in my code:






          <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
          <Palette tkCartesianPalette [seriesName]="meter.id">
          <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
          </Palette>
          </LineSeries>








          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389258%2fdynamically-set-color-of-line-spline-in-nativescript-ui-chart%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I found a solution to my problem, i added property binding to seriesName on both the LineSeries and to the PaletteEntry witch matches each line dynamically to a ID.



            Changes in my code:






            <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
            <Palette tkCartesianPalette [seriesName]="meter.id">
            <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
            </Palette>
            </LineSeries>








            share|improve this answer




























              1














              I found a solution to my problem, i added property binding to seriesName on both the LineSeries and to the PaletteEntry witch matches each line dynamically to a ID.



              Changes in my code:






              <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
              <Palette tkCartesianPalette [seriesName]="meter.id">
              <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
              </Palette>
              </LineSeries>








              share|improve this answer


























                1












                1








                1







                I found a solution to my problem, i added property binding to seriesName on both the LineSeries and to the PaletteEntry witch matches each line dynamically to a ID.



                Changes in my code:






                <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
                <Palette tkCartesianPalette [seriesName]="meter.id">
                <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
                </Palette>
                </LineSeries>








                share|improve this answer













                I found a solution to my problem, i added property binding to seriesName on both the LineSeries and to the PaletteEntry witch matches each line dynamically to a ID.



                Changes in my code:






                <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
                <Palette tkCartesianPalette [seriesName]="meter.id">
                <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
                </Palette>
                </LineSeries>








                <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
                <Palette tkCartesianPalette [seriesName]="meter.id">
                <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
                </Palette>
                </LineSeries>





                <LineSeries tkCartesianSeries [seriesName]="meter.id" *ngSwitchCase="'line'" [legendTitle]="meter.name + ' - ' + register.unit" [items]="register.data" stackMode="Stack" categoryProperty="timestamp" valueProperty="value">
                <Palette tkCartesianPalette [seriesName]="meter.id">
                <PaletteEntry tkCartesianPaletteEntry [strokeColor]="meter.color"></PaletteEntry>
                </Palette>
                </LineSeries>






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 10:22









                Johannes KraftJohannes Kraft

                479




                479






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53389258%2fdynamically-set-color-of-line-spline-in-nativescript-ui-chart%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    'app-layout' is not a known element: how to share Component with different Modules

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    WPF add header to Image with URL pettitions [duplicate]