TeeChart for .NETSteema Software SL



This browser does not seem to support HTML5 Canvas.

C# Code - multiple Chart Series types


@using Steema.TeeChart;
@using Steema.TeeChart.Styles;
@using System.IO;
@using System.Drawing;
@using ColorCode; 
@using TeeChartOnBlazor.Data;  //the project data

@code {

    public string chartName;
    public string title;

    public Task<string> GetJSChart(int chartType, int width, int height)
    {
        Steema.TeeChart.TChart mChart = new TChart();

        bool animate = false;

        switch (chartType) {
            case 0: Line line = new Line(mChart.Chart);
                animate=true;
                break;
            case 1: Points points = new Points(mChart.Chart);
                animate=true;
                break;
            case 2: Area area1 = new Area(mChart.Chart);
                Area area2 = new Area(mChart.Chart);
                //countSeries = 2;
                animate = true;
                break;
            case 3: break;
            case 5: Bubble bubble = new Bubble(mChart.Chart); animate = true; break;
            case 6: Candle candle = new Candle(mChart.Chart); break;
            case 7: Gantt gantt = new Gantt(mChart.Chart);
                break;
            case 31: Pie pie = new Pie(mChart.Chart); break;
            case 32: Donut donut = new Donut(mChart.Chart); break;
            case 33:
            case 34: CircularGauge cGauge = new CircularGauge(mChart.Chart); break;
        }

        var series = mChart.Series[0];

        mChart.Header.Text = ""; // series.Description + " series";

        mChart.Axes.Left.Title.Text = "value";

        foreach (Series s in mChart.Series)
        {
            if (series.GetType() == typeof(Bubble))
            {
                ((Bubble)(s)).Pointer.Gradient.Visible = true;
                ((Bubble)(s)).Pointer.Pen.Visible = false;
                s.FillSampleValues(50);
            }
            else if ((series.GetType() == typeof(Gantt)))
                s.FillSampleValues(9);
            else
                s.FillSampleValues();
        }

        if (mChart.Series.Count > 1)
        {
            if (mChart[0].MaxYValue() > mChart[1].MaxYValue())
                mChart.Axes.Left.SetMinMax(0, mChart[0].MaxYValue()+20);
            else
                mChart.Axes.Left.SetMinMax(0, mChart[1].MaxYValue()+20);
        }

        series.XValues.DateTime = true;
        //mChart.Axes.Bottom.Labels.Angle = 90;
        //mChart.Axes.Bottom.Increment = Steema.TeeChart.Utils.GetDateTimeStep(DateTimeSteps.OneDay);
        //mChart.Axes.Left.Title.Text = "µVal";

        if ((mChart.Series.Count == 1) && (series.GetType() != typeof(Gantt)))
            mChart.Axes.Left.SetMinMax(series.YValues.Minimum - 10, series.YValues.Maximum + 10);

        chartName = "dynoTeeChart";
        mChart.Export.Image.JScript.ChartName = chartName;

        MemoryStream ms = new MemoryStream();
        mChart.Export.Image.JScript.Width = width;
        mChart.Export.Image.JScript.Height = height;
        mChart.Export.Image.JScript.DoFullPage = false; //inline, no page <html> header tags

        if ((series.GetType() == typeof(Pie)) ||
                (series.GetType() == typeof(Donut)))
        {
            series.Marks.Visible = true;
            series.Marks.Arrow.Visible = false;
            series.Marks.Arrow.Color = Color.White;
            series.Marks.Transparent = true;
            series.Marks.Pen.Transparency = 100;
            series.Marks.Pen.Color = Color.White;
            series.Marks.Font.Color = Color.White;

            mChart.Export.Image.JScript.CustomCode = getCustomCodeOp2(mChart);
        }
        else
            mChart.Export.Image.JScript.CustomCode = getCustomCode1(animate, mChart);

        if ((series.GetType() == typeof(Gantt)))
        {
            ((Gantt)series).Brush.Gradient.Visible = false;
            ((Gantt)series).NextTasks[0] = 6;
            mChart.Axes.Left.Title.Text = "task";
        }

        if ((series.GetType() == typeof(CircularGauge)))
        {
            mChart.Axes.Left.Title.Text = "µHz";

            var customCode = new List<string>();

            if (chartType == 34)
            {
                customCode.Add("modGauge(" + chartName + ", " + chartName + ".series.items[0]" + ");");
                customCode.Add("setTimeout(modVal, 500);");
            }
            else
            {
                ((CircularGauge)(mChart[0])).Value = 0;
                customCode.Add(chartName + ".series.items[0]" + ".format.shadow.visible=false;");
                customCode.Add(chartName + ".series.items[0]" + ".back.visible=false;");
                customCode.Add("growVal(" + chartName + ");");
                customCode.Add("setTimeout(growVal, 500);");
            }

            mChart.Export.Image.JScript.CustomCode = customCode.ToArray();

        }

        title = mChart.Series[0].Description;

        mChart.Export.Image.JScript.Save(ms);

        ms.Position = 0;

        StreamReader reader = new StreamReader(ms);
        //setup our chart name, here 'dynoChartName'.
        string result = "<script> var " + chartName + "; " + reader.ReadToEnd() + "</script>";

        return Task.FromResult(result);
    }

    //general type characteristics
    string[] getCustomCode1(bool animate, TChart aChart)
    {
        var customCode = new List<string>();

        if (animate)
        {
            if (aChart[0].GetType() == typeof(Area))
            {
                customCode.Add("   //animation");
                customCode.Add("   animation = new Tee.SeriesAnimation();");
                customCode.Add("   animation.duration = 1700;");
                customCode.Add("   animation.kind = \"all\";");
                customCode.Add("   animation.mode = \"linear\";");
            }
            else
            {
                customCode.Add("   //animation");
                customCode.Add("   animation = new Tee.SeriesAnimation();");
                customCode.Add("   animation.duration = 900;");
                customCode.Add("   animation.kind = \"each\";");
                customCode.Add("   fadeAnimation = new Tee.FadeAnimation();");
                customCode.Add("   fadeAnimation.duration = 500;");
                customCode.Add("   fadeAnimation.fade.series = true;");
                customCode.Add("   fadeAnimation.fade.marks = true;");
                customCode.Add("   animation.mode = \"linear\"; ");
                customCode.Add("   fadeAnimation.mode = \"linear\";");
                customCode.Add("   animation.items.push(fadeAnimation);");
                customCode.Add("   ");
            }

            customCode.Add("   animation.animate(" + aChart.Export.Image.JScript.ChartName + ");");
        }

        if (aChart[0].GetType() == typeof(Candle))
        {
            customCode.Add(aChart.Export.Image.JScript.ChartName + ".axes.bottom.datetime = true;");
            customCode.Add(aChart.Export.Image.JScript.ChartName + ".axes.bottom.labels.dateFormat = \"shortDate\";");
            customCode.Add(aChart.Export.Image.JScript.ChartName + ".series.items[0].dateFormat = \"shortDate\";");

            //cursortool
            customCode.Add("var t = new Tee.CursorTool(" + aChart.Export.Image.JScript.ChartName + ");");
            customCode.Add("t.direction = \"both\";");
            customCode.Add(aChart.Export.Image.JScript.ChartName + ".tools.add(t);");
        }

        customCode.Add(aChart.Export.Image.JScript.ChartName + ".axes.bottom.labels.format.font.fill = \"rgba(0,0,0,0.6)\";");
        customCode.Add(aChart.Export.Image.JScript.ChartName + ".axes.bottom.labels.format.font.setSize(\"10px\");");
        customCode.Add(aChart.Export.Image.JScript.ChartName + ".series.items[0].marks.transparent = true;");

        //customCode.Add("hostChart = " + aChart.Export.Image.JScript.ChartName + ";");

        customCode.Add("chartFeatures(" + chartName + ");"); //call general setup enhancements
        customCode.Add("resizeC(" + chartName + ");");

        return customCode.ToArray();
    }

    //circulars, Pie Donut
    string[] getCustomCodeOp2(TChart aChart)
    {
        var customCode = new List<string>();

        //customCode.Add(chartName + ".series.items[0].marks.visible = false; ");
        customCode.Add(chartName + ".series.items[0].format.stroke.fill = \"white\"; ");
        customCode.Add(chartName + ".series.items[0].angleWidth = 0;");
        customCode.Add("animatedPie(" + chartName + ");");
        //customCode.Add("resizeC(" + chartName + ");");

        return customCode.ToArray();
    }

    public string getFormattedCode()
    {
        var chartCode = "<h3>C# Code - multiple Chart Series types</h3>";
        string strContents = TeeChartOnBlazor.Utils.getResource("genericStr.txt")

        var formatter = new HtmlFormatter();
        chartCode += formatter.GetHtmlString(strContents, Languages.CSharp);


        return chartCode;
    }
}