使用Winrt xaml工具包多线系列创建热图(频谱图)

时间:2016-02-03 11:48:39

标签: windows-store-apps winrt-xaml windows-8.1 heatmap spectrogram

我正在使用堆栈溢出中提供的算法在Windows应用商店8.1中创建热图。

第一种方法:

public Color HeatMapColor(decimal value, decimal min, decimal max)
{
    decimal val = (value - min) / (max - min);
    int r = Convert.ToByte(255 * val);
    int g = Convert.ToByte(255 * (1 - val));
    int b = 0;

    return Color.FromArgb(255,r,g,b);                                    
}

第二种方法:

    public Brush getColourTemp(int maxVal,int minVal ,double actual )
    {
        int maxVal = 70000000;
        int minVal = 100000;

        var midVal = (maxVal - minVal) / 2;
        int intR;
        int intG;
        int intB = Convert.ToInt32(Math.Round(0.0));

        if (actual >= midVal)
        {
            intR = 255;
            intG = Convert.ToInt32(Math.Round(255 * ((maxVal - actual) / (maxVal - midVal))));
        }
        else
        {
            intG = 255;
            intR = Convert.ToInt32(Math.Round(255 * ((actual) - minVal) / (midVal - minVal)));
        }
        //  Color background = Color.FromArgb(255, (byte)ran.Next(255), (byte)ran.Next(255), (byte)ran.Next(255));
        Color background = Color.FromArgb(255, (byte)intR, (byte)intG, (byte)intB);

        return new SolidColorBrush(background);

         //byte[] bytes = BitConverter.GetBytes(actual);
         //return new SolidColorBrush(Color.FromArgb(bytes[0], bytes[1], bytes[2], bytes[3]));


      //  return to_rgb(intR, intG, intB);
    }

但在这两种情况下蓝色为零的原因。我需要热图中的蓝色也可以帮助我。

我正在使用Winrt xaml工具包线图创建热图

代码详情

for (int i = 0; i <= 200; i++)
        {`enter code here`
            if (i > 25)
            {

                LineChart.Series.RemoveAt(0);
            }
            List<FinancialStuff> financialStuffList = new List<FinancialStuff>();
            LineSeries line = new LineSeries();
            line.Title = "";

            line.IndependentValuePath = "Name";
            line.DependentValuePath = "Amount";
            for (int j = 0; j < 256; j++)
            {
                financialStuffList.Add(new FinancialStuff() { Name = i, Amount = j - 130, FavoriteColor = ConvertTotalToRgb(i, j) });




            }
            line.ItemsSource = financialStuffList;

            line.DataPointStyle = style;
            LineChart.Series.Add(line);

            if (i >= 25)
            { 
            await Task.Delay(TimeSpan.FromSeconds(1));

            }

// *********** *********************************

   public Brush ConvertTotalToRgb(int val, int val1)
    {`enter code here`
        double actual = 0.0;
        int range = 70000000 - 100000;
        actual = data[val, val1];
        int main = Convert.ToInt32(255 * actual / range);
        string hexR = main.ToString("X2");
        int flip = Convert.ToInt32(255 * (1 - (actual / range)));
        string hexB = flip.ToString("X2");
        string colorValue = "#" + hexR + "00" + hexB;
        byte R = Convert.ToByte(colorValue.Substring(1, 2), 16);
        byte G = Convert.ToByte(colorValue.Substring(3, 2), 16);
        byte B = Convert.ToByte(colorValue.Substring(5, 2), 16);
        Color background = Color.FromArgb((byte)255, R, G, B);
        return new SolidColorBrush(background);
    }




        }
在i = 50之后性能非常差,它非常慢并且不加载可能是线图中的性能问题,因为它是巨大的数字。 如果任何机构可以说明改进或建议在Windows应用商店8.1开发中创建Spectrogram的其他方法,请提供帮助。

XAML页面

<Page   xmlns:Charting="using:WinRTXamlToolkit.Controls.DataVisualization.Charting" 
x:Class="MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Spect"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Grid >
    <Grid.Resources>
        <Style
            x:Key="ColorByPreferenceColumn"
           x:Name="abc"
            TargetType="Charting:LineDataPoint">
            <Setter Property="Background" Value="Transparent" />

            <Setter Property="Template"  >
                <Setter.Value>
                    <ControlTemplate
                        TargetType="Charting:LineDataPoint">


                        <Grid Background="{Binding FavoriteColor}">

                            <Polygon>
                                <Polygon.Fill>
                                    <LinearGradientBrush>
                                        <GradientStop Color="#77ffffff" Offset="0"/>
                                        <GradientStop Color="#00ffffff" Offset="1"/>
                                    </LinearGradientBrush>
                                </Polygon.Fill>

                            </Polygon>
                           </Grid>


                    </ControlTemplate>
                </Setter.Value>
            </Setter>

        </Style>

    </Grid.Resources>
    <Charting:Chart x:Name="LineChart"  HorizontalAlignment="Left" VerticalAlignment="Top"  Width="300" Height="600" Margin="208,107,0,0">

    </Charting:Chart>
    <Button Content="Data" HorizontalAlignment="Left" Margin="175,31,0,0" VerticalAlignment="Top" Click="Button_Click"/>
</Grid>

0 个答案:

没有答案