FlexChart - Add binding from Array inside an array

Posted by: viplav.setia on 9 November 2020, 8:29 am EST

    • Post Options:
    • Link

    Posted 9 November 2020, 8:29 am EST

    Hello Wijmo Support Team

    I am trying to create a multi series chart with some flexibility in data source.

    The size of the arrays is variable.

    
    public struct ChartRec
        {
          public double Value; // binding Y
          public string Label;  // name - series
          public string ValueUnit;
        }
    
        public class ChartRecId
        {
           double Id;  // this should be bindingX.
           ChartRec[] ChartRec;
        }
    
    // In javascript
    setSeries: function (pChart, pSeries) {
            var VarProg = "setSeries";
                if (pChart != null) {
                    for (var i = 0; i < pSeries.length; i++) {
                        var series = new wijmo.chart.Series();
                        series.binding = pSeries[i].binding;
                        series.name = pSeries[i].name;
                        pChart.series.push(series);
                    }
    
    

    I want to access the property “Label” and “Value” and set it to the series. But the size of this array is not fixed. BindingX is set to Id from class ChartRecId. If I set “Value” as binding in series it does not display the data in the chart.

    Can you share an example, how to achieve this use case?

    Kind Regards

  • Posted 9 November 2020, 8:32 am EST

    Series array is made from ChartRec array ```

    for(VarI = 0; VarI < VarChartRecArr.Length; VarI++)

    {

    VarChartSeries = new Chart.ChartSeries();

    VarChartSeries.binding = “Value” ;

    VarChartSeries.name = VarChartRecArr[VarI].Label;

    VarChartSeriesArr[VarI] = VarChartSeries;

    }

  • Posted 9 November 2020, 10:09 am EST

    Also tried this : ```

    public struct ChartRec

    {

    public double Id;

    public double Value;

    public string Label;

    public string ValueUnit;

    }

    
    Now the Id is same for different labels in the array. BindingX is set to "Id". Binding and name in series array set once for different labels with the first Id. Chart is rendered but data rendered is not ok. Data in array is {8,0,0}. Please see the image it shows all three columns as 0 and 8.[img]https://gccontent.blob.core.windows.net/forum-uploads/file-f69a8474-f4d4-413e-b87c-0baa6b5fc8a2.JPG[/img]
  • Posted 10 November 2020, 8:07 am EST

    Hi Viplav,

    As per my understanding, your data is structured like this. A single data item is stored in ChartRec, and the ChartRec array contains all the data items. Now, you are setting the Value as binding and the Label as the series name.

    But, the for loop will create different series for each of the data items. So, if you have 3 items in the array, then 3 different series with a single item will be created. That is why all the 3 rects in the chart are the same.

    Can you please let me know if you are trying to add different data items for different series? For example, a different data source of Sales series and different sources for Profit series

    Regards,

    Ashwin

  • Posted 10 November 2020, 9:10 am EST

    Hi Ashwin

    I understood the logic and solved it. Shifted the array filtering in javascript. Now I pass the source array from datagrid to a javascript function to set the chart item source.

    I had to create different item sources for different series. So I put the series creation in a loop running till the length of the array equal to different number of labels in the ChartRec(let labelarr save different labels). Then I created a new array according to each label filtering the ChartRec entries according to the label and then assigning this array as the item source to the series.

    Thank you for your time on this. Cheers!

    Kind Regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels