【问题标题】:How to draw a multiline chart using fusion charts?如何使用融合图绘制多线图?
【发布时间】:2021-01-08 16:27:57
【问题描述】:

我正在尝试以如下方法使用融合图绘制多线图:

private void GerarGraficoVarejo(string device)
        {
            DataTable ChartData2 = new DataTable();
            DataTable ChartData3 = new DataTable();
            DataTable ChartData4 = new DataTable();
            // Add columns to data table
            ChartData2.Columns.Add("Data", typeof(System.String));
            ChartData2.Columns.Add("Preço", typeof(System.Double));
            ChartData3.Columns.Add("Data", typeof(System.String));
            ChartData3.Columns.Add("Preço", typeof(System.Double));
            ChartData4.Columns.Add("Data", typeof(System.String));
            ChartData4.Columns.Add("Preço", typeof(System.Double));
            List<Data> datas = _repositorioVivoPreco.recuperarDatasVarejo();
            List<VivoPreco> v = _repositorioVivoPreco.ObterValoresMagalu(device, datas);
            List<VivoPreco> v2 = _repositorioVivoPreco.ObterValoresIplace(device, datas);
            List<VivoPreco> v3 = _repositorioVivoPreco.ObterValoresFastshop(device, datas);
            
            for (int i = 0; i < v.Count; i++)
            {
                ChartData2.Rows.Add(v[i].DataStrVarejo, v[i].ValorAparelhoVarejo);
            }
            for (int i = 0; i < v2.Count; i++)
            {
                ChartData3.Rows.Add(v2[i].DataStrVarejo, v2[i].ValorAparelhoVarejo);
            }
            for (int i = 0; i < v3.Count; i++)
            {
                ChartData4.Rows.Add(v3[i].DataStrVarejo, v3[i].ValorAparelhoVarejo);
            }
            
            StaticSource source2 = new StaticSource(ChartData2);
            StaticSource source3 = new StaticSource(ChartData3);
            StaticSource source4 = new StaticSource(ChartData4);
                
            DataModel model2 = new DataModel();
                
            model2.DataSources.Add(source2);
            model2.DataSources.Add(source3);
            model2.DataSources.Add(source4);
            Charts.LineChart column2 = new Charts.LineChart("fourthChart");

            // Set the width and the height of the chart
            column2.Width.Pixel(400);
            column2.Height.Pixel(400);
            column2.Data.Source = model2;

            // Set Chart Caption
            column2.Caption.Text = "Comparativo de Preços";                                   
            column2.Legend.Show = false;                   
            column2.XAxis.Text = "Comparativo Magalu";
            column2.YAxis.Text = "Vivo";
            column2.Scrollable = true;
            column2.ThemeName = FusionChartsTheme.ThemeName.FUSION;
            ViewData["GraficoVarejo"] = column2.Render();
        }

据我了解,每一行都是不同的数据源,还是我错了?因为只画了一条线。如何在我的图表中添加更多多行?

【问题讨论】:

    标签: c# fusioncharts


    【解决方案1】:

    FusionCharts.NET 目前未在积极开发中,您可以使用 FusionCharts ASP.NET 包装器并检查。

    它将为您提供创建 Chart 对象的条件,您可以在那里直接传递图表类型 JavaScript 别名和该图表类型的规定格式的数据源并检查。

    Chart newChart = new Chart("msline", "simplechart", "600", "400", "jsonurl", "data.json");
        chart.Text = newChart.Render();
    

    data.json 将包含为多系列折线图类型规定的数据源。

    如下所述。

    {
    "chart": {
        "caption": "Number of visitors last week",
        "subCaption": "Bakersfield Central vs Los Angeles Topanga",
        "xAxisName": "Day",
        "theme": "fusion"
    },
    "categories": [
        {
            "category": [
                {
                    "label": "Mon"
                },
                {
                    "label": "Tue"
                },
                {
                    "label": "Wed"
                },
                {
                    "vline": "true",
                    "lineposition": "0",
                    "color": "#6baa01",
                    "labelHAlign": "center",
                    "labelPosition": "0",
                    "label": "National holiday",
                    "dashed": "1"
                },
                {
                    "label": "Thu"
                },
                {
                    "label": "Fri"
                },
                {
                    "label": "Sat"
                },
                {
                    "label": "Sun"
                }
            ]
        }
    ],
    "dataset": [
        {
            "seriesname": "Bakersfield Central",
            "data": [
                {
                    "value": "15123"
                },
                {
                    "value": "14233"
                },
                {
                    "value": "25507"
                },
                {
                    "value": "9110"
                },
                {
                    "value": "15529"
                },
                {
                    "value": "20803"
                },
                {
                    "value": "19202"
                }
            ]
        },
        {
            "seriesname": "Los Angeles Topanga",
            "data": [
                {
                    "value": "13400"
                },
                {
                    "value": "12800"
                },
                {
                    "value": "22800"
                },
                {
                    "value": "12400"
                },
                {
                    "value": "15800"
                },
                {
                    "value": "19800"
                },
                {
                    "value": "21800"
                }
            ]
        }
    ],
    "trendlines": [
        {
            "line": [
                {
                    "startvalue": "17022",
                    "color": "#6baa01",
                    "valueOnRight": "1",
                    "displayvalue": "Average"
                }
            ]
        }
    ]
    

    }

    【讨论】:

      猜你喜欢
      • 2011-05-04
      • 2016-08-14
      • 2019-01-06
      • 1970-01-01
      • 2021-02-22
      • 2019-03-23
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多