示例#1
0
        private void LoadView()
        {
            // Paste your license key here.
            mNChartView.Chart.LicenseKey = "";

            // Margin to ensure some free space for the iOS status bar.
            mNChartView.Chart.CartesianSystem.Margin = new NChartMargin(10.0f, 10.0f, 10.0f, 20.0f);

            // We'll use 3D chart.
            mNChartView.Chart.DrawIn3D = true;

            // Create series that will be displayed on the chart.
            NChartSurfaceSeries series = new NChartSurfaceSeries();

            // Set data source for the series.
            series.DataSource = this;
            // Add series to the chart.
            mNChartView.Chart.AddSeries(series);

            // Create brush scale for series.
            // First create an array of solid color brushes with the scale colors.
            NChartBrush[] brushes =
            {
                new NChartSolidColorBrush(Color.Red),
                new NChartSolidColorBrush(Color.Yellow),
                new NChartSolidColorBrush(Color.Green),
                new NChartSolidColorBrush(Color.Cyan)
            };
            // Then create array of values that will indicate intervals to choose colors. Note, that the rule of getting brush
            // from the scale for given value x is:
            // if x <= values[0] then choose brush[0]
            // else if x > values[i] and x <= values[i + 1] then choose brush[i + 1], i = 0 .. n - 1, n is number of values
            // else if x > values[n - 1] then choose brush[n]
            // This is why array of brushes should have one more element than array of values.
            Number[] values = { (Number)(-0.5), (Number)(0.0), (Number)(0.5) };
            // Now create the brush scale itself.
            NChartBrushScale scale = new NChartBrushScale(brushes, values);

            // If you want smooth color transitions, let this line commented.
            // scale.IsGradient = false;
            // Assign the scale to the series.
            series.Scale = scale;

            // You probably want to have a legend on the chart displaying the scale. So create one.
            NChartScaleLegend scaleLegend = new NChartScaleLegend(scale);

            // Let it be on the left. Feel free to experiment with different locations.
            scaleLegend.BlockAlignment = NChartLegendBlockAlignment.Left;
            // Let it have a single column.
            scaleLegend.ColumnCount = 1;
            // Set the delegate for the legend to customize the strings in the entries. Do not assign the delegate if the
            // default behavior is ok for you.
            scaleLegend.ScaleDelegate = this;
            // Add the legend to the chart.
            mNChartView.Chart.AddScaleLegend(scaleLegend);

            // Update data in the chart.
            mNChartView.Chart.UpdateData();
        }
示例#2
0
 public string StringRepresentationOfRange(NSNumber from, NSNumber to, NChartScaleLegend scaleLegend)
 {
     // Perform a conversion of the values in the legend to string.
     // Return null from this method to see the default behavior.
     if (from != null && to == null)
     {
         return(string.Format("more than {0:0.#}", from.DoubleValue));
     }
     else if (from == null && to != null)
     {
         return(string.Format("less than {0:0.#}", to.DoubleValue));
     }
     else
     {
         return(string.Format("from {0:0.#} to {1:0.#}", from.DoubleValue, to.DoubleValue));
     }
 }